4
我該如何解決這個異常?BeanCurrentlyInCreationException Spring Boot
沒有Spring Boot一切正常。
所以問題出現在「應用」部分,對嗎?
捕捉到異常
BeanCurrentlyInCreationException: Error creating bean with name 'pooledConnectionFactory':
Requested bean is currently in creation: Is there an unresolvable circular reference?
應用
@ComponentScan
@EnableAutoConfiguration
@ImportResource("classpath:contexts/bean-locations.xml")
public class MyApp{
public static void main(String[] args) throws Exception {
new SpringApplication(MyApp.class).run(args);
}
}
通過導入
豆使用進口
<import resource="classpath*:contexts/database/datasource/base-data-source.xml"/>
<import resource="classpath*:contexts/database/datasource/pooled-data-source.xml"/>
第一個文件:
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">
<bean id="baseDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${connection.driverClassName}"/>
<property name="username" value="${connection.userName}"/>
<property name="password" value="${connection.password}"/>
<property name="url" value="${connection.url}"/>
</bean>
從進口
第二個文件:
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">
<bean id="pool" class="org.apache.commons.pool.impl.GenericObjectPool">
<property name="minEvictableIdleTimeMillis"><value>300000</value></property>
<property name="timeBetweenEvictionRunsMillis"><value>60000</value></property>
</bean>
<bean id="dataSourceConnectionFactory" class="org.apache.commons.dbcp.DataSourceConnectionFactory">
<constructor-arg><ref bean="baseDataSource"/></constructor-arg>
</bean>
<bean id="pooledConnectionFactory" class="org.apache.commons.dbcp.PoolableConnectionFactory">
<constructor-arg index="0"><ref bean="dataSourceConnectionFactory"/></constructor-arg>
<constructor-arg index="1"><ref bean="pool"/></constructor-arg>
<constructor-arg index="2"><null/></constructor-arg>
<constructor-arg index="3"><null/></constructor-arg>
<constructor-arg index="4"><value>false</value></constructor-arg>
<constructor-arg index="5"><value>true</value></constructor-arg>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.PoolingDataSource"
depends-on="pooledConnectionFactory">
<constructor-arg><ref bean="pool"/></constructor-arg>
</bean>
什麼是解決您的應用程序使用Spring Boot還需要使用Hibernate和HSQL?也許像測試一樣?公共無效beforeTestClass(TestContext的TestContext)拋出異常{ );拋出異常{0} {0} {0}數據庫連接.getConnection()。prepareStatement( 「SET DATABASE REFERENTIAL INTEGRITY FALSE」)。 } – Arthur