把事务放在service层,项目的目录结构是
+com
+owner
+dao
OwnerDao.java
+service
OwnerService.java
+param
+bp
+dao
BpDao.java
+service
BpService.javaspring +ibatis 下 配置aop 事务的 代码如下: <bean id="transactionManager_Apprsal"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource_apprsal"></property>
</bean>
<tx:advice id="txAdvice_Apprsal" transaction-manager="transactionManager_Apprsal">
<tx:attributes>
<tx:method name="login" propagation="REQUIRED" />
<tx:method name="signOut" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="copy*" propagation="REQUIRED"/>
<tx:method name="getSerial" propagation="REQUIRED"/>
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="allDAO_Apprsal"
expression="execution(* com.easepal..service.*Service.*(..))" />
<aop:advisor advice-ref="txAdvice_Apprsal" pointcut-ref="allDAO_Apprsal" />
</aop:config>但是这样配置的 不成功
+com
+owner
+dao
OwnerDao.java
+service
OwnerService.java
+param
+bp
+dao
BpDao.java
+service
BpService.javaspring +ibatis 下 配置aop 事务的 代码如下: <bean id="transactionManager_Apprsal"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource_apprsal"></property>
</bean>
<tx:advice id="txAdvice_Apprsal" transaction-manager="transactionManager_Apprsal">
<tx:attributes>
<tx:method name="login" propagation="REQUIRED" />
<tx:method name="signOut" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="copy*" propagation="REQUIRED"/>
<tx:method name="getSerial" propagation="REQUIRED"/>
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="allDAO_Apprsal"
expression="execution(* com.easepal..service.*Service.*(..))" />
<aop:advisor advice-ref="txAdvice_Apprsal" pointcut-ref="allDAO_Apprsal" />
</aop:config>但是这样配置的 不成功
解决方案 »
- 各位大神,js 中的Date.parse(new Date()) 在 java中 得到的值为什么不一样呢
- java页面请求跑批处理sql的问题
- 关于Criteria模糊查询及分页
- 跪求网页中图片播放器的制作实例
- ssh2的proxool连接池问题
- 求struts2,spring,hibernate二进制程序
- spring中如何根据时间调用dao中的方法
- 关于SSH框架的问题,在线等,万分感谢!
- j2ee除了做网站外还能做什么?
- 多线程同时操作不同的对象会引起意想不到的结果吗?为什么
- commons.betwixt xml和bean之间转换
- [高分求助]请问JPA中使用UUID可以用作复合主键吗?
SqlMapClientFactoryBean这个类是工厂类,不能够让ibatis自己加载<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="/WEB-INF/sqlmap-config.xml"/> <!-- iBatis sqlmap config 文件位置 -->
<property name="dataSource" ref="dataSource"/> <!-- 在SpringFramework配置文件中使用的数据源 -->
</bean>
<bean id="propertyConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:init.properties</value>
</property>
</bean>
<!-- ************************************************************************-->
<!-- ////////////////////////数据库(dbcp:apprasal)连接池配置*********************-->
<bean id="dataSource_apprsal"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="${jdbc.driverClassName}">
</property>
<property name="url" value="${jdbcapprsal.url}"></property>
<property name="username" value="${jdbcapprsal.username}"></property>
<property name="password" value="${jdbcapprsal.password}"></property>
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="30"></property>
<property name="maxWait" value="1000"></property>
<property name="defaultAutoCommit" value="false"></property>
<property name="removeAbandoned" value="true"></property>
<property name="removeAbandonedTimeout" value="60"></property>
<property name="logAbandoned" value="true"></property>
</bean>
<!-- sql map client 配置 -->
<bean id="sqlMapClient_apprsal"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation"
value="classpath:/ibatis-sql-map-config-easepal.xml" />
<property name="dataSource" ref="dataSource_apprsal" />
</bean>
<!-- ************************************************************************-->
<!-- //////////////////////ibatis事务代理配置///////////////////////////////-->
<!-- ************************************************************************-->
<!-- 配置哪些类哪些方法使用事务 -->
<bean id="transactionManager_Apprsal"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource_apprsal"></property>
</bean>
<tx:advice id="txAdvice_Apprsal" transaction-manager="transactionManager_Apprsal">
<tx:attributes>
<tx:method name="login" propagation="REQUIRED" />
<tx:method name="signOut" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="copy*" propagation="REQUIRED"/>
<tx:method name="getSerial" propagation="REQUIRED"/>
<!-- tx:method name="*" read-only="true" /-->
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="allDAO_Apprsal"
expression="execution(* *..service.*Serivce.*(..))" />
<aop:advisor advice-ref="txAdvice_Apprsal" pointcut-ref="allDAO_Apprsal" />
</aop:config>
<!-- ************************************************************************-->
<!-- ////////////////////// DAO /////////////////////////////////////////-->
<!-- ************************************************************************-->
<bean id="daoUserValidate"
class="com.succeed.apprsal.user.dao.impl.UserDaoImpl">
<property name="sqlMapClient">
<ref bean="sqlMapClient_apprsal" />
</property>
</bean>
<!-- //////////////////////////登录用户检查与会话检查/////////////////////////-->
<!-- ************************************************************************-->
<bean id="ValidateUserInterceptor" class="com.succeed.apprsal.service.ValidateUserInterceptor">
<property name="userDao" ref="daoUserValidate"></property>
<property name="sessionDao" ref="daoSessionValidate"></property>
</bean> <!-- ************************************************************************-->
<!-- //////////////////////CXF Services//////////////////////////////////////-->
<!-- ************************************************************************-->
<cxf:bus>
<cxf:features>
<cxf:logging />
</cxf:features>
<!-- sk added 2010-07-27
<cxf:inInterceptors>
<ref bean="ValidateUserInterceptor"/>
</cxf:inInterceptors>
-->
</cxf:bus>
<!-- 用户与会话管理 -->
<jaxws:endpoint xmlns:tns="http://succeed.com/apprsal/user/"
id="UserService" implementor="#Impl_UserService"
endpointName="tns:UserPort" serviceName="tns:UserService"
address="/UserService"/>
<bean id="Impl_UserService" class="com.succeed.apprsal.user.service.impl.UserServiceImpl">
<property name="userDao" ref="daoUser"></property>
<property name="sessionDao" ref="daoSession"></property>
</bean>
<jaxws:endpoint xmlns:tns="http://easepal.com/param/"
id="ParamService" implementor="#Impl_ParamService"
endpointName="tns:ParamPort" serviceName="tns:ParamService"
address="/ParamService"/>
<bean id="Impl_ParamService" class="com.easepal.param.service.impl.ParamServiceImpl">
<property name="bpDao" ref="daoParamBp"></property>
<property name="tempDao" ref="daoParamTemp"></property>
<property name="userDao" ref="daoEuser"></property>
</bean>
expression="execution(* com.easepal..service.*Service.*(..))"
和你给com.succeed.apprsal.service.ValidateUserInterceptor
com.succeed.apprsal.user.service.impl.UserServiceImpl
com.easepal.param.service.impl.ParamServiceImpl
这个都不匹配吧....
expression="execution(* com.easepal..service.*Service.*(..))" 这个要符合所以 service 类的事务,可以不用考虑 com.succeed.apprsal.user.service.impl.UserServiceImpl
expression="execution(* com.easepal..service.*Service.*(..))"这个匹配不了
com.easepal.param.service.impl.ParamServiceImpl
我猜测这样可以匹配你的所有service
expression="execution(* com.easepal..service.impl.*Service*.*(..))"
参考下http://hotpepper.iteye.com/blog/141350 这个吧
<aop:pointcut id="serviceOperation"
expression="execution(* com.xyh.*.*.dao.*.*(..))" />
<aop:advisor pointcut-ref="serviceOperation"
advice-ref="txAdvice" />
</aop:config>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:ibatis/mybatis-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
<property name="mapperInterface" value="com.hy.portal.product.dao.UserManageMapper" />
</bean>
方式 ,数据都没有进入到数据库中,我觉得是事务没有提交 ,这个事务管理都配置好了 ,应该会自动提交吧 ,为什么数据没有插入到数据库中呢
com.easepal.param.service.impl.ParamServiceImpl 这个类不匹配吗?
2、可能是数据库连接池的原因
<property name="defaultAutoCommit" value="false"></property>
删除此行看看
这个业务逻辑层的代码 public String saveParam(EuserComm euserComm, Bp[] bp, Temp[] temps, Bo[] bo) {
if(bp==null||bp.length==0){
throw new RuntimeException("RC002");
}
BpPojo[] bpList=new BpPojo[bp.length];
for(int i=0;i<bp.length;i++){
BpPojo bpPojo=new BpPojo();
Bp bpObj=bp[i];
bpPojo.setBpId(UUIDGenerator.getUUID());
bpPojo.setRegisterId(bpObj.getRegisterId());
bpPojo.setUserName(userDao.getUserNameByRegId(bpObj.getRegisterId()));
bpPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm", bpObj.getMeasureTime()));
bpPojo.setProductNo(euserComm.getProductNo());
bpPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm", euserComm.getSendTime()));
bpPojo.setSp(bpObj.getSp());
bpPojo.setDp(bpObj.getDp());
int pp=bp[i].getSp()-bp[i].getDp();
bpPojo.setPp(pp);
bpList[i]=bpPojo;
}
bpDao.saveBp(bpList);
if(temps==null||temps.length==0){
throw new RuntimeException("RC002");
}
TempPojo[] tempList=new TempPojo[temps.length];
String userName=userDao.getUserNameByRegId(temps[0].getRegisterId());
for(int i=0;i<temps.length;i++){
TempPojo tempPojo=new TempPojo();
Temp temp=temps[i];
tempPojo.setTempId(UUIDGenerator.getUUID());
tempPojo.setRegisterId(temp.getRegisterId());
tempPojo.setProductNo(euserComm.getProductNo());
tempPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm",euserComm.getSendTime()));
tempPojo.setUserName(userName);
tempPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm",temp.getMeasureTime()));
tempPojo.setTempValue(Float.parseFloat(temp.getTempValue()));
tempList[i]=tempPojo;
}
tempDao.saveTemp(tempList);
return "RC001";
}
2、尝试修改下<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED" rollback-for="Throwable"/>
对所有异常都回滚