我在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.JdbcTemplate
的org.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
类。它工作正常。