Reputation: 2488
Spring Web results in circular reference under the following condition
Below is my analysis.
One workaround was to ensure that Spring first loads a dummy bean say B0, that no bean will depend on.
Java Configuration:
@Configuration
@DependsOn("testBean2")
@EnableTransactionManagement
public class TestConfig
{
@Bean
public PlatformTransactionManager transactionManager()
{
DriverManagerDataSource dataSource = new DriverManagerDataSource();
// MySQL database we are using
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/db");// change url
dataSource.setUsername("username");// change userid
dataSource.setPassword("password");// change pwd
PlatformTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
return transactionManager;
}
}
XML Configuration:
<?xml version="1.0" encoding="UTF-8"?>
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<aop:aspectj-autoproxy />
<context:component-scan base-package="test.config" />
<bean id="testBean2" class="test.beans.TestBean2" />
<bean id="testTransactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="audit">PROPAGATION_REQUIRES_NEW</prop>
</props>
</property>
</bean>
<bean id="testBean1" class="org.springframework.aop.framework.ProxyFactoryBean"
depends-on="testBean2">
<property name="target">
<bean class="test.beans.TestBean1" />
</property>
<property name="interceptorNames">
<list>
<value>testTransactionInterceptor</value>
</list>
</property>
</bean>
</beans>
Upvotes: 0
Views: 312
Reputation: 18235
Move your @Bean
declaration to a @Configuration
class.
It will prevent one bean method called twice
Upvotes: 0