我在Spring中有以下数据库配置:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="url" value="jdbc:dburl" />
            <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="username" value="username" />
            <property name="password" value="passworf" />
            <property name="removeAbandoned" value="true" />
            <property name="initialSize" value="3" />
            <property name="maxActive" value="5" />
        </bean>


用于从数据库加载属性值的附加配置。

<bean id="config1" class="org.apache.commons.configuration.DatabaseConfiguration">
        <constructor-arg type="javax.sql.DataSource" ref="dataSource" />
        <constructor-arg index="1" value="tablename1" />
        <constructor-arg index="2" value="columnname" />
        <constructor-arg index="3" value="columnvalue" />
    </bean>

    <bean id="configFactory1"
        class="org.springmodules.commons.configuration.CommonsConfigurationFactoryBean">
        <constructor-arg ref="config1" />
    </bean>

    <!-- DB Properties Initialization -->
    <bean id="configurationPlaceHolder1"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders" value="false"/>
        <property name="properties" ref="configFactory1" />
    </bean>

    <bean id="config2" class="org.apache.commons.configuration.DatabaseConfiguration">
        <constructor-arg type="javax.sql.DataSource" ref="dataSource" />
        <constructor-arg index="1" value="tablename2" />
        <constructor-arg index="2" value="columnname" />
        <constructor-arg index="3" value="columnvalue" />
    </bean>

    <bean id="configFactory2"
        class="org.springmodules.commons.configuration.CommonsConfigurationFactoryBean">
        <constructor-arg ref="config2" />
    </bean>

    <!-- DB Properties Initialization -->
    <bean id="configurationPlaceHolder2"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders" value="false"/>
        <property name="properties" ref="configFactory2" />
    </bean>


DAO配置出现问题:

    <!-- DAO Bean which is causing issue -->
    <bean id="problematicBean" class="com.example.ProblematicDAOImpl" scope="singleton">
      <property name="dataSource"  ref="dataSource" />
    </bean>


当我启动应用程序时,我停留在以下行:

    17 Feb 2014 15:39:58,981 -  main - DEBUG -
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:691)  -
Executing prepared SQL query
            17 Feb 2014 15:39:58,983 -  main - DEBUG -
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:625)  -
Executing prepared SQL statement [ SQL STATEMENT ]


17 Feb 2014 15:39:59,000 -  main - DEBUG -
 org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:110)
- Fetching JDBC Connection from DataSource


此行之后,应用程序挂起并且不响应。它也不会引发异常。

我已经做了以下检查:


maxActive值增加。
initialSize值增加。
检查在- SQL STATEMENT中正在执行的Query Browser


**更新**

我进一步调试了代​​码,该代码在方法org.springframework.jdbc.core.JdbcTemplateorg.springframework.jdbc.core.JdbcTemplate.execute(PreparedStatementCreator, PreparedStatementCallback<T>)中挂起@line 642

代码行如下:

if (this.nativeJdbcExtractor != null) {
                psToUse = this.nativeJdbcExtractor.getNativePreparedStatement(ps);
            }
            T result = action.doInPreparedStatement(psToUse);//Hangs at this line
            handleWarnings(ps);
            return result;

最佳答案

我你有。它解决了我自己。我正在使用NamedParameterJdbctemplate来调用不带任何参数的查询。在spring api中执行准备好的语句时,此操作挂起。我将其切换为JdbcTempalte类。它工作正常。

08-18 11:26