@Configuration
public class TransactionManagerConfig {
private final String PROPAGATION_NAME_CHANGE = "PROPAGATION_REQUIRED,-Exception";
private final String PROPAGATION_NAME_SELECT = "PROPAGATION_REQUIRED,-Exception,readOnly";
@Autowired
private DataSourceTransactionManager transactionManager;
@Bean(name = "transactionManagerAdvice")
public TransactionInterceptor transactionInterceptor() throws Exception {
Properties properties = new Properties();
properties.setProperty("add*", PROPAGATION_NAME_CHANGE);
properties.setProperty("save*", PROPAGATION_NAME_CHANGE);
properties.setProperty("insert*", PROPAGATION_NAME_CHANGE);
properties.setProperty("update*", PROPAGATION_NAME_CHANGE);
properties.setProperty("delete*", PROPAGATION_NAME_CHANGE);
properties.setProperty("get*", PROPAGATION_NAME_SELECT);
properties.setProperty("find*", PROPAGATION_NAME_SELECT);
return new TransactionInterceptor(transactionManager, properties);
}
@Bean
public BeanNameAutoProxyCreator txProxy() {
BeanNameAutoProxyCreator beanNameAutoProxyCreator = new BeanNameAutoProxyCreator();
beanNameAutoProxyCreator.setInterceptorNames("transactionManagerAdvice");
beanNameAutoProxyCreator.setBeanNames("*Service", "*ServiceImpl");
beanNameAutoProxyCreator.setProxyTargetClass(true);
return beanNameAutoProxyCreator;
}
}