首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

Spring中的AOP,以及宣言式事务 @Transactional无法拦截事务

2011-12-25 
Spring中的AOP,以及声明式事务 @Transactional无法拦截事务DAO中@Repositorypublic class TestDao extends

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>

大侠救命!

[解决办法]
<tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/> 

中的 proxy-target-class="true" 我记得应该不是默认值,就是不用默认的jdk代理

看LZ service 类的内容应该没为该类创建 Interface ,那么proxy-target-class="true"设置的是对的

给你几个方案

1,取默认值,就是proxy-target-class="true"不要了,给service穿件个接口

2,检查下第三方代理类的cglib,看看是否存在版本等问题

以上情况是在没报错的前提下

把hibernate的show_sql打开看看有输出么,如果有输出还没数据那就是隔离级别的问题了
[解决办法]
顶..
[解决办法]
有输出是不是数据库没数据?

你用的什么数据库
[解决办法]
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>


[解决办法]
<bean id="listeningclozetitleService" parent="proxytemplate">
<property name="target">
<bean class="com.gainuo.elec.service.impl.ListeningClozeTitleServiceImpl">
<property name="dao">
<bean class="com.gainuo.elec.dao.hibernate.ListeningClozeTitleDAOImpl">
<property name="sessionFactory">
<ref local="mysessionFactory"/>
</property>
</bean>
</property>
</bean>
</property>
</bean>

<bean id="proxytemplate" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
<!-- 事务代理模板 -->
<property name="transactionManager">
<ref local="myTransactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
[解决办法]
dddddddddddddddddddddd
[解决办法]
o
[解决办法]
也一直弄不懂AOP呀,来学习!
[解决办法]
接分


PS: 


我的目标是 ---->

^_^

[解决办法]
有深度的问题,关注下
[解决办法]
hao tie jiafena
[解决办法]
jf
[解决办法]
顶一个
[解决办法]
关注关注啦
[解决办法]
我以前也遇到过。
[解决办法]
DDDDD
[解决办法]
mark
[解决办法]
ding

热点排行