项目采用spring声明式事务管理,但是到后期才发现一些不规范的做法,模块中本来不需要事务控制的方法(method)也被声明在事务控制之下;请问各位大侠如何在改动量最小的情况下纠正呢?
示例如下:
// 事务性的服务接口
[code="java"]package x.y.service;
public interface FooService {
Foo getFoo(String fooName);
Foo getFoo(String fooName, String barName);
void insertFoo(Foo foo);
void updateFoo(Foo foo);
void methodeTemp(Foo foo);//这个方法不想在事务控制之下...
}[/code]
[code="java"]<!-- from the file 'context.xml' -->
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
tx:attributes
/tx:attributes
/tx:advice
aop:config
...
...
...
...
...
...
[/code]
问:现在想把方法 methodeTemp 脱离事务管理,如何实现呢?
注:修改代码,将类似方法methodeTemp 从模块中转移出来的做法,对本项目不适合;因为改动量会很大...
[b]问题补充:[/b]
修改这个配置文件
tx:attributes
/tx:attributes
/tx:advice
说明:
虽然这样可以,但是不能保证其他模块(service)中有同名的方法需要在事务控制之下的。
当然也可以把不需要事务控制的方法名称加一个前缀,这样就可以匹配控制,但是这样又要修改代码了,修改量会很大...因为这个方法不只是一处在调用...