public IAccountService getAccountService() {
Proxy.newProxyInstance(accountService.getClass().getClassLoader(),
accountService.getClass().getInterfaces(),
new InvocationHandler() {
/**
* 添加事务的支持
* */
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object rtValue = null;
try {
//开启事务
txManager.start();
//执行操作
rtValue = method.invoke(accountService,args);
//提交事务
txManager.commit();
//返回结果
return rtValue;
}catch (Exception e){
//回滚操作
txManager.rollback();
throw new RuntimeException(e);
}finally {
//释放资源
txManager.release();
}
}
});
return ?创建代理对象这里应该返回什么?
} |
|