我有个问题要问你。我有一个有2个方法的组件。第一个方法需要附加到从链中存在的另一个组件启动的外部事务(我使用Spring Integration),第二个方法必须附加(对于我的应用程序设计),以执行另一个事务。我想要的行为是,当第二个方法抛出异常时,第一个方法启动,并重新附加到另一个事务以完成他的工作。我尝试使用Spring Framework的“嵌套”传播来实现这一点,但没有成功。
示例如下:
public ComponentClassInterface{
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor=Exception.class) /*but i have used NESTED without success and I don't want use the same transaction */
public ObjectMessage activate(ObjectMessage message);}
public ComponentAbstractClass implements ComponentClassInterface{
public void updateObjectMessage(ObjectMessage message){
/*To obtain an attached instance of previously persisted message*/
ObjectMessage message = daoMessage.getMessageByID(message.getID);/*Here i can't retreive the message...the transaction isn't yet attached*/
message.setSomeProperty("ChangedPropertyValue");
daoMessage.updateItem(message);
}
@Override
public abstract ObjectMessage activate(ObjectMessage message);}
public ComponentConcreteClass extends ComponentAbstractClass{
@Override
public ObjectMessage activate(ObjectMessage message){
............ doSomeStuff ............
}}
我们的目标是找到一种解决方案,允许我不重写/重新思考应用程序流程,并像以前一样管理类。
问候
达米亚诺
发布于 2011-04-29 22:26:52
Spring中的事务是通过AOP和代理来支持的。这意味着如果一个类实例的方法调用同一实例的另一个方法,它不会通过Spring代理调用该方法,Spring也不能拦截该调用并为您启动一个新的事务。您需要将带有REQUIRES_NEW传播的方法放入另一个Spring组件中。
https://stackoverflow.com/questions/5833281
复制相似问题