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

spring注解式事务加在方法下失败,求人指点

2012-09-14 
spring注解式事务加在方法上失败,求人指点!在service方法上加入了@Transactional(readOnly false, propa

spring注解式事务加在方法上失败,求人指点!
在service方法上加入了
@Transactional(readOnly = false, propagation = Propagation.REQUIRED,rollbackFor=Exception.class) 
使得方法加载不到了。。不知道是少哪里原因,以下spring配置文件

Java code
<beans    xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:context="http://www.springframework.org/schema/context"     xmlns:p="http://www.springframework.org/schema/p"    xmlns:tx="http://www.springframework.org/schema/tx"    xmlns:aop="http://www.springframework.org/schema/aop"    xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd    http://www.springframework.org/schema/context       http://www.springframework.org/schema/context/spring-context-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">        <context:annotation-config /><bean id="dataSource"        class="org.apache.commons.dbcp.BasicDataSource">        <property name="driverClassName" value="${jdbc.driverClassName}"></property>        <property name="url" value="${jdbc.url}"></property>        <property name="username" value="${jdbc.username}"></property>        <property name="password" value="${jdbc.password}"></property>         <property name="maxActive">                <value>100</value>          </property>          <property name="maxWait">              <value>1000</value>          </property>          <property name="maxIdle">             <value>30</value>          </property>          <property name="defaultAutoCommit">             <value>true</value>             </property>          <property name="removeAbandoned">             <value>true</value>            </property>          <property name="removeAbandonedTimeout">              <value>60</value>            </property>    </bean><bean id="sessionFactory"        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">        <property name="dataSource">            <ref bean="dataSource" />        </property>        <property name="hibernateProperties">            <props>                <prop key="hibernate.dialect">                    org.hibernate.dialect.Oracle9Dialect                </prop>                <prop key="hibernate.show_sql">true</prop>                <prop key="hibernate.format_sql">true</prop>            </props>        </property></bean>        <!-- 事务管理对象-->    <bean id="transactionManager"         class="org.springframework.orm.hibernate3.HibernateTransactionManager">        <property name="sessionFactory">            <ref local="sessionFactory"/>        </property>    </bean><tx:annotation-driven transaction-manager="transactionManager" /><bean id="TCashaccountDAO"        class="com.skyTeam.junjunxia.user.dao.TCashaccountDAO">        <property name="sessionFactory">            <ref bean="sessionFactory" />        </property>    </bean></beans>



另外工程中引入的spring包有


spring.jar
spring-beans.jar
spring-context.jar
spring-core.jar
spring-aop.jar
spring-context-support.jar
spring-web.jar
spring-tx.jar
spring-jms.jar
spring-orm.jar
spring-webmvc.jar
spring-webmvc-portlet.jar
spring-webmvc-struts.jar

[解决办法]
你的TCashaccountDAO,最好也去用注解,xml和annotation不要混用
在<context:annotation-config />
下面加上
<context:component-scan base-package="com.skyTeam" />
[解决办法]

探讨

加载不到报什么错?没加事务注解能加载?
<aop:aspectj-autoproxy proxy-target-class="true"/>
配置文件加这个试试

[解决办法]
你这个信息有点少,我有一个经验不知道对你是否有帮助,spring的注解如果是在同一个类里面相互调用的话,这个方法上面的注解是不会起作用的,必须是外部的类来掉注解了的方法才会起作用

热点排行