SPRING:请求的bean目前正在创建:是否存在无法解析的循环引用

时间:2018-01-24 15:48:39

标签: java spring hikaricp spring-bean

我试图实施hikari,但我有这个错误:

/META-INF/datasource.beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?

我的配置:

<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
    <property name="poolName" value="abc_connection_pool" />
    <property name="dataSourceClassName" value="com.informix.jdbcx.IfxDataSource"/>
    <property name="maximumPoolSize" value="100" />     
    <property name="connectionTimeout" value="500" />
    <property name="validationTimeout" value="300" />
    <property name="maxLifetime" value="30000" />
    <property name="transactionIsolation" value="1" />
    <property name="dataSourceProperties">
    <props>
        <prop key="url">${jdbc.url}</prop>
        <prop key="user">${jdbc.username}</prop>
        <prop key="password">${jdbc.password}</prop>
    </props>
    </property>
</bean>

<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
    <constructor-arg ref="hikariConfig" />
</bean> 

环境

HikariCP version: HikariCP-java6 2.3.13
JDK version     : 1.6
Database        : Informix
Driver version  : Ibm.informix.jdbc 3.00.JC3 

我更改了Hikari运行的上一个池,我收到了该错误

1 个答案:

答案 0 :(得分:0)

已配置父标记 beans default-autowire =“byName” 我厌恶它并解决了这个问题。

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
    default-autowire="byName">

<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
    <property name="poolName" value="abc_connection_pool" />
    <property name="dataSourceClassName" value="com.informix.jdbcx.IfxDataSource"/>
    <property name="maximumPoolSize" value="100" />     
    <property name="connectionTimeout" value="500" />
    <property name="validationTimeout" value="300" />
    <property name="maxLifetime" value="30000" />
    <property name="transactionIsolation" value="1" />
    <property name="dataSourceProperties">
    <props>
        <prop key="url">${jdbc.url}</prop>
        <prop key="user">${jdbc.username}</prop>
        <prop key="password">${jdbc.password}</prop>
    </props>
    </property>
</bean>

<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
    <constructor-arg ref="hikariConfig" />
</bean>

</beans>