我怎么能修复这个例外?
没有Spring Boot一切正常.
所以问题出现在“App”部分,对不对?
抓到了异常
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);
}
}
通过导入Bean使用
<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具有Database initialization功能,与您的DataSource配置冲突.请参见DataSourceInitializer类.它尝试在创建之前获取数据源.
要修复您的应用,您可以
>使用属性禁用初始化程序
spring.datasource.initialize=false
>排除数据源自动配置,因为您有自己的配置
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})