我有一个bean(SettingService),它用@Transactional注解装饰,并注入另一个bean,在这个bean被调用的上下文刷新事件。Bean在ContextRefreshedEvent中没有获得事务代理4.2.5
public class DefaultConfigManager
implements ApplicationListener<ContextRefreshedEvent>, ConfigManager {
@Autowired
private SettingService service;
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
System.out.println("Proxy: " + AopUtils.isJdkDynamicProxy(service));
String key = service.getSystemSetting("KEY");
}
交易工作一般公和上述工程方法如预期在Spring 4.1.9,其中所述的println指示SettingService豆是动态JDK代理(事务处理)。
现在升级到4.2.5春天在此之后突然开始抛出以下错误:
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
at org.springframework.orm.hibernate4.SpringSessionContext. currentSession(SpringSessionContext.java:134)
at org.hibernate.internal.SessionFactoryImpl. getCurrentSession(SessionFactoryImpl.java:993)
和println的指示SettingService不再/已装修的代理,这意味着没有交易将开始。
根据Spring文档,在发布ContextRefreshedEvent时,应该完成所有的bean和后处理器。
Hibernate事务管理器在应用上下文中配置,tx:annotation-driven元素就位,@Transactional注释放在实现上(而不是接口),系统中没有循环依赖关系。 Hibernate版本:4.2.20.Final。
这是否与任何人打铃?有没有什么典型的原因,为什么在Spring 4.2中不再使用ContextRefreshedEvent的事务代理bean? Spring 4.1和4.2之间的任何常见错误或变化需要注意?
我们正在使用XML配置和组件扫描的组合。当完全删除组件扫描时,这个问题就消失了。虽然不是真正的解决方案。 – lars