Spring中的AOP,以及宣告式事務 @Transactional無法攔截事務
DAO中
@Repository
public class TestDao extends BaseHibernateDao {
public void test(){
String hql = " update ZTest set uname = ? where id = 5 ";
Query q = this.getSession(true).createQuery(hql);
q.setString(0, "x");
q.executeUpdate();
String hql2 = " update ZTest set unadfme = ? where id = 5";
Query q2 = this.getSession(true).createQuery(hql2);
q2.executeUpdate();
}
}
SERVICE中
@Service
public class ServiceTest extends BaseService {
@Autowired
TestDao testDao;
@Override
public void destroy() {
}
@Override
public void init() {
}
@Transactional
public void testTransactional(){
testDao.test();
}
}
CONTROLLER中
@Controller
public class PLetterController extends BaseController {
@Autowired
ServiceTest serviceTest;
@RequestMapping("/testT.do")
public void test(Writer writer) throws Exception{
serviceTest.testTransactional();
}
}
SPRING 管理 HIBERNATE
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
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">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName">
<value>org.logicalcobwebs.proxool.ProxoolDriver </value>
</property>
<property name="url">
<value>jdbc:oracle:thin:省略.......... </value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="packagesToScan">
<list>
<value>com.XXXXXXX.domain </value>
</list>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation">
<value>WEB-INF/classes/hibernate.cfg.xml </value>
</property>
</bean>
<!--
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor" ref="transactionInterceptor"/>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributeSource">
<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
</property>
</bean>
-->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/>
</beans>
參考資料
http://japi.javaeye.com/blog/285800
http://mrzhangtufu.javaeye.com/blog/241341
http://blog.exis.com/colin/archives/2005/07/18/spring-12s-java-5-based-transaction-annotations/
http://www.21java.com/html/19/t-1719.html
http://justry28.javaeye.com/blog/264241
http://topic.csdn.net/u/20080612/18/69d920fe-20d6-404b-9c3b-1c2656be0f12.html
無法回滾
@Repository
public class TestDao extends BaseHibernateDao {
public void test(){
String hql = " update ZTest set uname = ? where id = 5 ";
Query q = this.getSession(true).createQuery(hql);
q.setString(0, "x");
q.executeUpdate();
String hql2 = " update ZTest set unadfme = ? where id = 5";
Query q2 = this.getSession(true).createQuery(hql2);
q2.executeUpdate();
}
}
SERVICE中
@Service
public class ServiceTest extends BaseService {
@Autowired
TestDao testDao;
@Override
public void destroy() {
}
@Override
public void init() {
}
@Transactional
public void testTransactional(){
testDao.test();
}
}
CONTROLLER中
@Controller
public class PLetterController extends BaseController {
@Autowired
ServiceTest serviceTest;
@RequestMapping("/testT.do")
public void test(Writer writer) throws Exception{
serviceTest.testTransactional();
}
}
SPRING 管理 HIBERNATE
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
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">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName">
<value>org.logicalcobwebs.proxool.ProxoolDriver </value>
</property>
<property name="url">
<value>jdbc:oracle:thin:省略.......... </value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="packagesToScan">
<list>
<value>com.XXXXXXX.domain </value>
</list>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation">
<value>WEB-INF/classes/hibernate.cfg.xml </value>
</property>
</bean>
<!--
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor" ref="transactionInterceptor"/>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributeSource">
<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
</property>
</bean>
-->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/>
</beans>
參考資料
http://japi.javaeye.com/blog/285800
http://mrzhangtufu.javaeye.com/blog/241341
http://blog.exis.com/colin/archives/2005/07/18/spring-12s-java-5-based-transaction-annotations/
http://www.21java.com/html/19/t-1719.html
http://justry28.javaeye.com/blog/264241
http://topic.csdn.net/u/20080612/18/69d920fe-20d6-404b-9c3b-1c2656be0f12.html
無法回滾
相關文章
- Spring宣告式事務@Transactional使用Spring
- Spring事務的介紹,以及基於註解@Transactional的宣告式事務Spring
- Spring @Transactional 宣告式事務揭祕Spring
- Spring宣告式事務控制原理之宣告式事務的重要元件在AOP中的應用Spring元件
- Spring AOP 日誌攔截器的事務管理Spring
- spring宣告式事務無法關閉sessionSpringSession
- Spring的事務管理(二)宣告式事務管理Spring
- Spring中@Transactional事務使用陷阱Spring
- Spring-宣告式事務Spring
- 三 Spring 宣告式事務Spring
- Spring宣告式事務控制Spring
- Spring MVC + Mybatis + Spring Aop宣告式事務管理沒有作用SpringMVCMyBatis
- @Transactional spring 配置事務 注意事項Spring
- Spring的四種宣告式事務的配置-Hibernate事務Spring
- spring宣告式事務管理配置Spring
- spring事物配置,宣告式事務管理和基於@Transactional註解的使用Spring
- Spring宣告式事務注意點,以及不生效情況Spring
- 深刻理解Spring宣告式事務Spring
- 全面分析 Spring 的程式設計式事務管理及宣告式事務管理Spring程式設計
- Spring-AOP事務Spring
- Spring筆記(4) - Spring的程式設計式事務和宣告式事務詳解Spring筆記程式設計
- Springboot資料庫事務處理——Spring宣告式事務Spring Boot資料庫
- 五(二)、spring 宣告式事務xml配置SpringXML
- 【Spring註解】事務註解@TransactionalSpring
- Spring宣告式事務的兩種實現方式Spring
- Spring宣告式事務純xml模式回顧SpringXML模式
- JavaEE(12)Spring整合Mybaits、宣告式事務JavaSpringAI
- Spring boot +mybatis 實現宣告式事務管理Spring BootMyBatis
- 分散式事務之Spring事務與JMS事務(二)分散式Spring
- 宣告式事務能否和程式設計式事務巢狀使用?程式設計巢狀
- EAS_AOP分散式事務分散式
- Spring中@Transactional事務回滾例項及原始碼Spring原始碼
- Java開啟事務(@Transactional)Java
- 筆記53-Spring jdbcTemplate&宣告式事務筆記SpringJDBC
- SpringMVC、MyBatis 宣告式事務管理SpringMVCMyBatis
- Spring非同步Async和事務Transactional註解Spring非同步
- Spring事務管理—aop:pointcut expression解析SpringExpress
- 四、事務拓撲(Transactional Topolgoy)Go