我正在开发一个Spring-MVC应用程序,在该应用程序中,我为不同类型的任务定义了2个数据源。当前,在从XML到Java的迁移过程中,我偶然发现了添加新HibernateTransactionManager对象@Transactional才能正常工作的要求。对于2个不同的数据源,我有2个单独的SessionFactory实例。但是,当我尝试使用辅助数据源创建另一个HibernateTransactionManager实例时,出现了一个非唯一异常。
我要发布的配置是否需要辅助HibernateTransactionManager实例,还是1个就足够了?如果需要,如何创建一个?谢谢你。
错误日志:
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined: expected single matching bean but found 2: primary_tx,extended_tx
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:368)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
at org.springframework.transaction.interceptor.TransactionAspectSupport.determineTransactionManager(TransactionAspectSupport.java:367)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:271)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springfram
典型的服务层方法:
@Service
@Transactional("primary_tx")
public class ChatRoomMembersServiceImpl implements ChatRoomMembersService{
private final ChatRoomMembersDAO chatRoomMembersDAO;
@Autowired
public ChatRoomMembersServiceImpl(ChatRoomMembersDAO chatRoomMembersDAO){
this.chatRoomMembersDAO = chatRoomMembersDAO;
}
}
典型的DAO层方法:
@Repository
@Transactional("primary_tx")
public class ChatRoomMembersDAOImpl implements ChatRoomMembersDAO{
@Autowired
@Qualifier(value = "sessionFactory_origin")
private SessionFactory sessionFactory;
@Autowired
@Qualifier(value = "sessionFactory_extended")
private SessionFactory sessionFactory_extended;
}
现在,每当需要时,我指的是扩展的SessionFactory实例。现在,我用来注释了需要扩展sessionFactory的DAO层方法secondary_tx,但是它不起作用。谢谢你。:-)
翻阅古今
相关分类