[英]Spring Web - Circular Reference on enabling AspectJ & Transaction Management
Spring Web results in circular reference under the following condition 在以下条件下,Spring Web产生循环引用
Below is my analysis. 以下是我的分析。
One workaround was to ensure that Spring first loads a dummy bean say B0, that no bean will depend on. 一种解决方法是确保Spring首先加载一个虚假的bean,即B0,没有bean依赖。
Java Configuration: Java配置:
@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配置:
<?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>
Move your @Bean
declaration to a @Configuration
class. 将您的
@Bean
声明移到@Configuration
类。
It will prevent one bean method called twice 它将防止一个调用两次的bean方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.