spring配置aop事务管理后异常报错后事务未回滚

图片说明
我的配置如图
图片说明

2个回答

你的切面代码里try {

    } catch (Exception e) {
    roback
    }里没有回滚。

@Transactional

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
spring aop 事务控制 为何异常时不会滚呢?

spring事务相关配置 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="upd*" propagation="REQUIRED" rollback-for="java.lang.Exception"/> <tx:method name="del*" propagation="REQUIRED" /> <tx:method name="*" propagation="SUPPORTS" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="canyin" expression="execution(* com.laphone.base.baseservice.*.*(..)) ||execution(* com.laphone.canyin.*.service.*.*(..)) || execution(* com.laphone.canyin.*.*.service.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="canyin" /> </aop:config> service中的方法updForOrder()使用了try catch(Exception e); 但是出现异常时还是有部分数据存到了数据库,说明异常时没有回滚。 请问xdjm们有没有碰到过这种问题,csdn上有很多这种问题,但几乎都试过,没能解决 分不多,海涵~

spring事务 insert成功之后出现异常不回滚

``` @Transactional(rollbackFor=RuntimeException.class, propagation = Propagation.REQUIRED,isolation= Isolation.READ_UNCOMMITTED) ``` 声明式配置 ``` 前面一个insert操作 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动开启事务回滚 throw new RuntimeException(); ``` insert未回滚 这两行没用在service层还是出现了脏数据

spring+mybatis异常不回滚

代码如下: applicationContext-mybatis.xml ``` <bean id="sSF" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath:com/telchina/**/*.xml"></property> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.telchina"></property> <property name="sqlSessionFactoryBeanName" value="sSF"></property> </bean> <!-- 事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" > <property name="dataSource" ref="dataSource" /> </bean> <!-- 拦截器方式配置事务 --> <tx:advice id="transactionAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.RuntimeException"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="transactionPointcut" expression="execution(* com.telchina.app.service.impl.*Impl.*(..))" /> <aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" /> </aop:config> ``` ``` @Service("demoService") public class DemoServiceImpl implements DemoService { @SuppressWarnings("rawtypes") @Override public String rollbackTest(List demoList) { // TODO Auto-generated method stub Iterator itr = demoList.iterator(); while (itr.hasNext()) { Map demoMap = (Map) itr.next(); demoMapper.updateDemo(demoMap); throw new RuntimeException("rollbackTest"); } return ""; } } ``` List中传入了两个对象,总是能更新一个,事务不回滚,愁死了,求各位大侠指点!!!!

请大牛帮忙解决个问题,spring+jpa(全标注配置) 事务不回滚

在一个事务中,插入两条数据,有一条数据已存在数据库中,执行程序后应该发生异常,事务进行回滚,不插入数据库任何数据;但程序执行后发生了异常,但事务没有回滚,数据库又新增了一条数据,请大牛帮忙解决一下! [b]配置文件:[/b] <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/20<script type="text/javascript" src="http://www.iteye.com/javascripts/tinymce/themes/advanced/langs/zh.js"></script><script type="text/javascript" src="http://www.iteye.com/javascripts/tinymce/plugins/javaeye/langs/zh.js"></script>01/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <!-- 服务功能配置 --> <!-- 数据源配置 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost/test" /> <property name="username" value="root" /> <property name="password" value="" /> </bean> <!-- JPA EntityManagerFactory --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="database" value="MYSQL" /> <property name="showSql" value="yes" /> </bean> </property> </bean> <!-- 事务配置 --> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" /> <context:component-scan base-package="com.spring"/> </beans> [b]dao层:[/b] package com.spring.test6.esp.sample001.dao; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import com.spring.test6.esp.sample001.model.User; @Service("UserDAO") public class UserDAOImpl implements UserDAO { private EntityManager em; @PersistenceContext public void setEntityManager(EntityManager em) { this.em = em; } public EntityManager getEntityManager() { return this.em; } public void create(User user) { em.persist(user); } } [b]service层:[/b] package com.spring.test6.esp.sample001.service; import org.springframework.transaction.annotation.Transactional; import com.spring.test6.esp.common.service.BaseServiceImpl; import com.spring.test6.esp.sample001.model.User; @Transactional public class UserServiceImpl extends BaseServiceImpl<User> implements UserService { public UserServiceImpl() { super(User.class); } @Override @Transactional(noRollbackForClassName = "java.lang.Throwable") public void create1() { try { User user = new User(); user.setId(68); user.setName("caterpillar"); user.setAge(30); User user1 = new User(); user1.setId(82); user1.setName("caterpillar"); user1.setAge(30); this.dao.create(user1); this.dao.create(user); } catch (RuntimeException re) { throw re; } } } [b]调用:[/b] package com.spring.test6.esp.sample001.controller; /* * 鍩烘湰CRUD鎿嶄綔 */ import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.spring.test6.esp.sample001.service.UserService; public class UserFormController { public static void main(String[] args) { String[] locations = {"beans6.xml"}; ApplicationContext ctx = new ClassPathXmlApplicationContext(locations); UserService _userService = (UserService) ctx.getBean("UserService"); try { _userService.create1(); } catch (Exception e) { System.out.println(e.getClass().getName()); } } } [b]问题补充:[/b] 能写详细一些吗,比如在那里加,谢谢! [b]问题补充:[/b] 还是不行啊!还是报异常,插数据! [b]问题补充:[/b] <property name="validationQuery" value="select * from dual"/> <property name="testOnReturn" value="true"/> 也不行!是我代码那块写错了吗? [b]问题补充:[/b] 配了,运行还是老样子! [b]问题补充:[/b] 去掉了!还是那样子!

Spring aop配置事务出错。

**出现 无法加载Failed to load ApplicationContext ,注释掉aop的配置能正常运行** ``` <?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:context="http://www.springframework.org/schema/context" 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-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> <!-- 依赖关系 dao->jdbcTemplate->dataSource --> <!-- 读取配置文件 --> <context:property-placeholder location="db.properties" /> <!-- dataSource --> <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driverClass}" /> <property name="jdbcUrl" value="${jdbc.jdbcUrl}" /> <property name="user" value="${jdbc.user}" /> <property name="password" value="${jdbc.password}" /> </bean> <!-- dao --> <bean name="accountDao" class="com.sikiedu.dao.AccountDaoImpl"> <property name="dataSource" ref="dataSource" /> </bean> <!-- service --> <bean name="accountService" class="com.sikiedu.service.AccountServiceImpl"> <property name="ad" ref="accountDao" /> </bean> <!-- 配置事务核心管理器 不同平台不一样 --> <bean name="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 事务通知 --> <tx:advice id="txAdivce" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="transferAccounts" isolation="DEFAULT" propagation="REQUIRED" read-only="false" /> </tx:attributes> </tx:advice> ** <!-- 配置aop --> <aop:config> <aop:pointcut expression="execution(* com.sikiedu.service.*ServiceImpl.*(..))" id="txPc" /> <aop:advisor advice-ref="txAdivce" pointcut-ref="txPc" /> </aop:config> </beans> ** ``` ``` @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:applicationContext.xml") public class TxTest { @Resource(name="accountService") private AccountService as; @Test public void Test() { as.transferAccounts(); } ``` java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.aspectj.util.LangUtil at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:275) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) ... 25 more Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.aspectj.util.LangUtil at org.aspectj.weaver.reflect.ReflectionWorld.<init>(ReflectionWorld.java:52) at org.aspectj.weaver.tools.PointcutParser.setClassLoader(PointcutParser.java:221) at org.aspectj.weaver.tools.PointcutParser.<init>(PointcutParser.java:207) at org.aspectj.weaver.tools.PointcutParser.getPointcutParserSupportingSpecifiedPrimitivesAndUsingSpecifiedClassLoaderForResolution(PointcutParser.java:168) at org.springframework.aop.aspectj.AspectJExpressionPointcut.initializePointcutParser(AspectJExpressionPointcut.java:242) at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:221) at org.springframework.aop.aspectj.AspectJExpressionPointcut.obtainPointcutExpression(AspectJExpressionPointcut.java:198) at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:177) at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:225) at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:288) at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:320) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:126) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:95) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:76) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:347) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:429) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ... 39 more ![图片说明](https://img-ask.csdn.net/upload/201907/30/1564452632_681928.png)

springboot mybatis sqlserver 事务无法回滚

springboot mybatis sqlserver 事务无法回滚 控制台提示如下 明明已经加入了事务管理,抛出异常还是不会回滚 13:58:03.061 [http-nio-9000-exec-15] INFO c.n.c.u.d.DynamicDataSourceContextHolder - [setDataSourceType,26] - 切换到SQLSERVER_ERP数据源 Creating a new SqlSession Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@595277fa] will be managed by Spring SQL提示巴拉巴拉 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] from current transaction SQL提示巴拉巴拉 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] from current transaction **执行插入sql,插入后执行 int a = 1/0;** Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] 13:58:03.313 [http-nio-9000-exec-15] ERROR c.n.f.e.GlobalExceptionHandler - [notFount,64] - 运行时异常: java.lang.ArithmeticException: / by zero at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl.excuteUpdateAndInsert(YygsHkhxServiceImpl.java:274) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl.hexiao(YygsHkhxServiceImpl.java:245) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl.ywyzidonghexiao(YygsHkhxServiceImpl.java:84) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl$$FastClassBySpringCGLIB$$a7103f4.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88) at com.nbpt.framework.aspectj.DataSourceAspect.around(DataSourceAspect.java:53) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl$$EnhancerBySpringCGLIB$$971cc6f.ywyzidonghexiao(<generated>) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl$$FastClassBySpringCGLIB$$a7103f4.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl$$EnhancerBySpringCGLIB$$da33e29b.ywyzidonghexiao(<generated>) at com.nbpt.web.yygs.hkhxkh.YygsHkhxController.ywyzidonghexiao(YygsHkhxController.java:90) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908) at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) 13:58:03.316 [http-nio-9000-exec-15] WARN o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - [logException,194] - Resolved [java.lang.ArithmeticException: / by zero]

spring + mybatis 事物不起作用,无法回滚

spring + mybatis 事物不起作用,无法回滚:求解 设置如下: <!-- proxy-target-class默认"false",更改为"ture"使用CGLib动态代理 --> <aop:aspectj-autoproxy proxy-target-class="true" /> <!-- 基于Druid数据库链接池的数据源配置 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="initialSize" value="${pool.initialSize}" /> <property name="minIdle" value="${pool.minIdle}" /> <property name="maxActive" value="${pool.maxActive}" /> <property name="maxWait" value="${pool.maxWait}" /> <property name="timeBetweenEvictionRunsMillis" value="${pool.timeBetweenEvictionRunsMillis}" /> <property name="minEvictableIdleTimeMillis" value="${pool.minEvictableIdleTimeMillis}" /> <property name="testWhileIdle" value="true" /> <property name="testOnBorrow" value="true" /> <property name="testOnReturn" value="false" /> <property name="validationQuery" value="${jdbc.validationQuery}" /> <property name="filters" value="config" /> <property name="connectionProperties" value="config.decrypt=true;config.decrypt.key=${jdbc.publickey}" /> </bean> <!-- 将数据源映射到sqlSessionFactory中 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mapperLocations" value="classpath*:mapper/*.Mapper.xml" /> <property name="configLocation" value="classpath:config/mybatis-config.xml" /> </bean> <!-- SqlSession模板类实例 --> <bean id="sessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="close"> <constructor-arg index="0" ref="sqlSessionFactory" /> </bean> <!--======= 事务配置 Begin ================= --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- <aop:pointcut id="txPointcut" expression="execution(* com.enjoy.system.service..*(..)) or execution(* com.enjoy.commodity.service..*(..))" /> --> <aop:config> <aop:pointcut id="txPointcut" expression="(execution(* com.enjoy.system.service..*(..)) or execution(* com.enjoy.commodity.service..*(..)))" /> <aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="set*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="edit*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="init*" propagation="REQUIRED" /> <tx:method name="get*" propagation="REQUIRED" read-only="true" /> <tx:method name="count*" propagation="REQUIRED" read-only="true" /> <tx:method name="find*" propagation="REQUIRED" read-only="true" /> <tx:method name="list*" propagation="REQUIRED" read-only="true" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> 求解!!

hibernate 手动控制事务回滚失败

spring配置: <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="com.mysql.jdbc.Driver" /> <property name="jdbcUrl" value="jdbc:mysql://192.168.0.124:3306/art8k?useUnicode=true&amp;characterEncoding=utf-8" /> <property name="user" value="root" /> <property name="password" value="123456" /> <property name="initialPoolSize"><value>5</value></property> <property name="minPoolSize"><value>20</value></property> <property name="maxPoolSize"><value>100</value></property> <property name="acquireIncrement"><value>5</value></property> <property name="maxIdleTime"><value>100</value></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=true hibernate.format_sql=false </value> </property> <property name="packagesToScan" value="com.art8k.platform.*.*.bean"/> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true"/> <tx:method name="find*" read-only="true"/> <tx:method name="list*" read-only="true"/> <tx:method name="*" rollback-for="Exception"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="operation" expression="execution(* com.art8k.platform..service.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="operation" /> </aop:config> <bean id="dao" class="com.art8k.platform.dao.IDaoManager"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <bean id="baseService" abstract="true" class="com.art8k.platform.service.BaseService"> <property name="dao"> <ref bean="dao"/> </property> </bean> BaseService.java public BaseService() { if (SpringUtil.getWebApplicationContext()!=null && SpringUtil.getWebApplicationContext().getBean("dao") != null) { this.dao = (IDaoManager) SpringUtil.getWebApplicationContext().getBean("dao"); } } /** * 数据库操作 dao */ @SuppressWarnings("unchecked") @Resource protected IDaoManager dao; @SuppressWarnings("unchecked") public void setDao(IDaoManager dao) { this.dao = dao; } @SuppressWarnings("unchecked") public IDaoManager getDao() { return dao; } IDaoManager.java public class IDaoManager<T, P, PK extends Serializable> extends HibernateDaoSupport implements GeneraDAO<T, P, PK> { /** * <p> * 持久化业务逻辑数据对象 ,无返回值 * </p> */ public void saveIObject(final T object) { getHibernateTemplate().save(object); } /** * <p> * 持久化业务逻辑数据对象,新增或者更新 ,无返回值 * </p> * * @param object * T 业务逻辑数据对象 */ public void saveOrUpdateIObject(final T object) { getHibernateTemplate().saveOrUpdate(object); } 我自己的service集成BaseService,我在service里的一个方法内插入两条数据,如果出现异常,把本次对数据库的所有操作回滚,现在问题是回滚失败,代码如下: public int saveProduct(HmProduct hmProduct) { int result = ConstanData.SUCCESSCODE; Session sessions = null; sessions = this.getDao().getHibernateTemplate().getSessionFactory().openSession(); sessions.beginTransaction(); try { sessions.save(hmProduct); HmProductLog hmProductLog = new HmProductLog(); hmProductLog.setProductId(hmProduct.getId()); hmProductLog.setPrice(hmProduct.getPrice()); hmProductLog.setCreateTime(new Date()); sessions.save(hmProductLog); } catch (Exception e) { // TODO Auto-generated catch block sessions.getTransaction().rollback(); result = ConstanData.FAILURECODE; e.printStackTrace(); }finally{ sessions.close(); } return result; }

springboot+mybatis事务使用

大家好我使用springboot集成mybatis,在一个业务处理中使用for循环插入数据, 比如list中有十条数据,for执行mappe.insert(user)十次,我的理解是方法上使用了 ``` @Transactional ``` 如果后面insert报错,前面插入的数据也会回滚,但是实际没有,我的理解哪里有问题吗?

Spring框架,如何使切点中的异常不影响原来的业务

各位高手,我现在遇到了一个关于切点异常处理的问题,试了很多方法没有办法解决,所以想请问一下,有没有人有解决的办法,具体的情况如下: 我们采用SpringMVC框架,其中有一个Service类,提供一个addOrder的方法来新增订单。现在突然间有了一个需求,要求,对所有订单中属于某一公司的订单进行识别,并将其通过接口同步到第三方业务系统。 为了不破坏原本的业务流程,决定采用AOP编程,为addOrder方法织入一个环绕性的切点,一旦addOrder执行成功,就判断addOrder新增的订单是不是属于某个公司的,如果是则调用接口。如果不是,直接返回。这样的话就可以不改动原有的代码。一旦某天取消这个同步功能,只要去掉相应的配置就可以了。 一切都开发完,功能也很正常。但是在测试的过程中发现一个问题: 如果通信过程总发生了异常,会反过来影响原来的Service类的addOrde方法,导致数据库事物回滚。造成业务失败。这与我们的初衷完全相背离了。 我们尝试,用如下的方法来调用消息发送类: try { pjp.proceed(); //如果没有抛出任何异常,则证明处理成功 }catch (Throwable e) { log.error(e); //出现了错误,业务被终止,不需要处理 throw e; } try{ Order order=(Order) pjp.getArgs()[0];//获取第一个参数,就是新增的订单 sendOrder(order); } catch(Throwable e) {//出现任何异常,认为消息同步失败 return; } 即急用try-catch 将所有的throwable 捕获下来。 但是,实际过程中,发现,虽然捕获了异常,但service却依然回滚了,仍然被AOP的异常所影响。 请问各位,对于这种情况有什么办法可以处理? 万分感谢!

在一个有事务管理的service中进行两次不同数据库的操作,事务提交报错

![图片说明](https://img-ask.csdn.net/upload/201907/03/1562123815_328240.png) ![图片说明](https://img-ask.csdn.net/upload/201907/03/1562123894_774333.png) 代码执行结束aop事务提交报错,改怎么解决。

昨天弄到半夜,Spring2.5 Ibatis2.3 注解注入,配置事务管理不成功

<p>Spring2.5+Ibatis2.3 用注解方式注入,事务管理不成功。。。。。<br><br><br>业务层:<br></p> <pre name="code" class="java">@Service public class UserServiceImpl implements UserService { @Resource private UserDao userDao; public UserDao getUserDao() { return userDao; } public void setUserDao(UserDao userDao) { this.userDao = userDao; } @Override public void insertUser() { User user = new User(); user.setName("a"); userDao.addUser(user); //第2次插入会出错 User user2 = new User(); user2.setName("bmmmmmmmmmmmmm"); userDao.addUser(user2); } }</pre> <p>  <br><br><br>DAO:</p> <pre name="code" class="java">public class BaseDaoImpl extends SqlMapClientDaoSupport{ @Resource(name = "sqlMapClient") private SqlMapClient sqlMapClient; @PostConstruct public void initSqlMapClient(){ super.setSqlMapClient(sqlMapClient); } } </pre> <p> </p> <p> </p> <pre name="code" class="java">@Repository("userDao") public class UserDaoImpl extends BaseDaoImpl implements UserDao{ public UserDaoImpl() { super(); System.out.println("UserDaoImplUserDaoImplUserDaoImplUserDaoImpl"); } @Override public void addUser(User user) { this.getSqlMapClientTemplate().insert("User.addUser",user); } }</pre>   <p>test-servlet.xml:</p> <p> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt; &lt;context:annotation-config /&gt; &lt;context:component-scan base-package="com.edgar" /&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /&gt; &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/view/" p:suffix=".jsp" /&gt; &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" p:defaultEncoding="utf-8" /&gt; &lt;/beans&gt; </pre> <p> </p> <p>applicationContext.xml:</p> <p> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" 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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;property name="driverClassName"&gt; &lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt; &lt;/property&gt; &lt;property name="url"&gt; &lt;value&gt;jdbc:mysql://127.0.0.1:3306/psimserver?autoReconnect=true&amp;amp;useUnicode=true&amp;amp;characterEncoding=GBK&lt;/value&gt; &lt;/property&gt; &lt;property name="username"&gt; &lt;value&gt;psim&lt;/value&gt; &lt;/property&gt; &lt;property name="password"&gt; &lt;value&gt;psim&lt;/value&gt; &lt;/property&gt; &lt;property name="initialSize"&gt; &lt;value&gt;50&lt;/value&gt; &lt;/property&gt; &lt;property name="maxActive"&gt; &lt;value&gt;1000&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"&gt; &lt;property name="configLocation"&gt; &lt;value&gt;classpath:sql-map-config.xml&lt;/value&gt; &lt;/property&gt; &lt;property name="dataSource"&gt; &lt;ref bean="dataSource" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt; &lt;property name="dataSource"&gt; &lt;ref local="dataSource" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt; &lt;bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate"&gt; &lt;property name="sqlMapClient"&gt; &lt;ref bean="sqlMapClient" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- &lt;bean id="userService" class="com.edgar.service.impl.UserServiceImpl"&gt; &lt;property name="userDao"&gt; &lt;ref bean="userDao" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="userDao" class="com.edgar.dao.impl.UserDaoImpl"&gt; &lt;property name="sqlMapClientTemplate"&gt; &lt;ref bean="sqlMapClientTemplate" /&gt; &lt;/property&gt; &lt;/bean&gt; --&gt; &lt;aop:config&gt; &lt;aop:pointcut id="serviceMethods" expression="execution(* com.edgar.service.*.*(..))" /&gt; &lt;aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods" /&gt; &lt;/aop:config&gt; &lt;aop:aspectj-autoproxy /&gt; &lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt; &lt;tx:attributes&gt; &lt;tx:method name="insert*" propagation="REQUIRED" isolation="DEFAULT" /&gt; &lt;tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT" /&gt; &lt;tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT" /&gt; &lt;tx:method name="*" propagation="REQUIRED" isolation="DEFAULT" /&gt; &lt;/tx:attributes&gt; &lt;/tx:advice&gt; &lt;bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" /&gt; &lt;/beans&gt; </pre> <p> </p> <p>Service中第二次插入记录会报错,事务应该回滚,但是没有回滚</p> <p><strong><br></strong></p> <p><span style="color: #ff6600; font-size: small;"><strong>如果我把Service中的 @Resource 和 UserDaoImpl中的 @Repository("userDao") 这两个注解去掉,在applicationContext.xml中直接通过bean配置</strong></span></p> <p><span style="color: #ff6600; font-size: small;"><strong>(上面配置中userService和userDao是注释掉了,取消注释),事务管理是起作用的。</strong></span></p> <p> </p> <p>代码有点长,但是大家应该一看就明白,昨天弄了一晚上,很着急。。 我到底哪里配错了啊??</p> <p> </p>

为什么exception无法捕获spring 中proceedingJoinPoint类中的 proceed的异常?

在Spring AOP的环绕通知控制事务时,使用proceedingJoinPoint类中的 proceed 放行原始方法时需要抛出一个异常,但只能使用Throwable捕获

getCurrentSession()获得的sessoin不受Spring的事务管理?这个问题困扰了我好几天。

之前项目里没有spring,一切正常,dao里用到的session都是通过sessionFactory.getCurrentSession()获得的,手工启动事务,filter统一提交或回滚。 <br />说明hibernate的配置没有问题。 <br /> <br />然后引入了spring。 <br /> <br />spring的配置里的hibernate是这么初始化的,应该也无问题 <br /><pre name="code" class="java"> &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; &lt;property name="configLocation" value="classpath:hibernate.cfg.xml"/&gt; &lt;/bean&gt; </pre> <br /> <br />然后声明式事务管理 <br /><div class="quote_title">引用</div><div class="quote_div">&lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; <br /> &lt;property name="sessionFactory"&gt;&lt;ref bean="sessionFactory"/&gt;&lt;/property&gt; <br />&lt;/bean&gt; <br />&lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt; <br /> &lt;tx:attributes&gt; <br /> &lt;tx:method name="*" propagation="REQUIRED"/&gt; <br /> &lt;tx:method name="get*" propagation="REQUIRED" read-only="true"/&gt; <br /> &lt;/tx:attributes&gt; <br />&lt;/tx:advice&gt; <br />&lt;aop:config&gt; <br /> &lt;aop:pointcut id="systemService" expression="execution(* com.orm.system.service.*.*(..))"/&gt; <br /> &lt;aop:advisor advice-ref="txAdvice" pointcut-ref="systemService"/&gt; <br />&lt;/aop:config&gt; <br /></div> <br /> <br />Dao都是继承自HibernateDaoSupport,接受spring注入的sessionFactory实例。切面是配置在service层的,service的方法里调用dao的方法。 <br /> <br />问题出来了。 <br /> <br />在任何一个Dao里面 <br />如果使用this.getSession()则session正常关闭,调用多次也没问题。 <br />如果使用this.getHibernateTemplate().getSessionFactory().getCurrentSession(),始终打开1个session并且不能关闭。 <br /> <br />我觉得如果使用this.getSession()正常,所以事务配置应该是没有问题的。 <br />而且有一点,如果是通过getCurrentSession()获得的session必须要beginTransaction,不然报错,而this.getSession()则不用。 <br /> <br />后来我配置了OpenSessionInViewFilter,发现这里打开和关闭的session和dao里面this.getSession()获得的session是同一个,而getCurrentSession()获得的不是同一个, <br />this.getSession().getTransaction().isActive() = true, <br />getCurrentSession().getTransaction().isActive() = false, <br /> <br />说明getCurrentSession()获得的session并不在事务管理里。 <br /> <br />我看了很多东西,一些是说getCurrentSession()在spring的事务管理,一些是说通过调用spring创建的sessionFactory的getCurrentSession()方法获得的session在spring的事务管理(难道还有不通过spring创建的sessionFactory?)。我做了一些测试,结果表明自始至终sessionFactory都只有一个实例。 <br /> <br /> <br />所以我得出结论,虽然sessionFactory受spring管理,但是直接从sessionFactory获取的session(不管是openSession还是getCurrentSession)不受spring的事务管理,是原生的Hibernate session。 <br /> <br />不知道我这样理解是否有问题,还是我哪里做错了得出了错误的结果?<br/><strong>问题补充</strong><br/>没有人研究过这个问题?还是太新手了不屑回答啊?

Spring事务的问题,bulkUpdate,或query.executeUpdate

今天在测试spring任务调度时,突然发现我配的声明事务不起作用了,找了好久才发现不是我的事务的问题,是我在Dao中用了一个方法有问题 方法如下: public void updateByIds(final Set<String> updateIds)throws DaoException{ try { String queryString="update from Yaoyueyingyue y set y.state='2' where y.yaoyueid in (?)"; getHibernateTemplate().bulkUpdate(queryString, updateIds.toArray()); } catch (Exception e) { e.printStackTrace(); throw new DaoException(this.getClassName()+e.getMessage()); } updateIds是一个包含要更新的编号集合,我发现用这个方法在我Manager中调用Dao事务就不起作用了,后来又改成这样 public void updateByIds(final Set<String> updateIds)throws DaoException{ try { getHibernateTemplate().execute(new HibernateCallback(){ final String hql="update Yaoyueyingyue y set y.state=2 where yaoyueid in (:yaoyueid)"; public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query=session.createQuery(hql); query.setParameterList("yaoyueid", updateIds); query.executeUpdate(); return null; } }); } catch (Exception e) { e.printStackTrace(); throw new DaoException(this.getClassName()+e.getMessage()); } } 事务还是不行,这两个方法好像不受spring AOP事务管理,只要执行到这个Dao的方法就自动提交了,出来异常也不能回滚,真是郁闷,小弟对这块不是很明白,为什么事务就不行了呢,希望那位牛人,帮我解释下,谢谢了, 我的spring声明事务大概如下: <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown"> <value>true</value></property> </bean> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> <property name="transactionTimeout" value="300"/> </bean> <bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager"><ref bean="atomikosTransactionManager" /></property> <property name="userTransaction"><ref bean="atomikosUserTransaction" /></property> </bean> <aop:config> <!-- This definition creates auto-proxy infrastructure based on the given pointcut, expressed in AspectJ pointcut language. Here: applying the advice named "txAdvice" to all methods on classes named PetStoreImpl. --> <aop:advisor pointcut="execution(* com.goal.log.manager.*.*(..))" advice-ref="txAdvice" /> <aop:advisor pointcut="execution(* com.goal.system.manager.*.*(..))" advice-ref="txAdvice" /> </aop:config> <!-- @Transactional 时要使用下面一行 --> <!-- <tx:annotation-driven transaction-manager="springTransactionManager" proxy-target-class="true"/> --> <!-- Transaction advice definition, based on method name patterns. Defaults to PROPAGATION_REQUIRED for all methods whose name starts with "insert" or "update", and to PROPAGATION_REQUIRED with read-only hint for all other methods.--> <!-- 引用springTransactionManager --> <tx:advice id="txAdvice" transaction-manager="springTransactionManager"> <tx:attributes> <tx:method name="save*" rollback-for="java.lang.Exception"/> <tx:method name="insert*" rollback-for="java.lang.Exception"/> .... <tx:method name="*" read-only="true" rollback-for="java.lang.Exception"/> </tx:attributes> </tx:advice> atomikosTransactionManager这个东西不用管,是一个开源的支持JTA分布式的JAR,希望有人能够为我解答........ [b]问题补充:[/b] 谢谢你的解答,但是我还是不明白你的意思,你是指我的Dao中用了内部类吗,你所指的 “调用updateByIds方法 的代码 跳出你的当前类 然后在别的类调用当前了类的接口中的方法updateByIds ”是指什么意思,能不能说明白点,谢谢了!!! [b]问题补充:[/b] 谢谢你的答复,你的意思我也理解,但好像不是这个问题,因为我并没有像你说的那样在类的内部调用,我的所有方法都是在业务逻辑层调用的Manager层,Manager层我是在Spring中配置了的声明事务的,我给你据个例子: 这两个方法都是Dao中的 方法一: [code="java"] public void updateByIds(final Set<String> updateIds)throws DaoException{ try { /*String queryString="update from Yaoyuepub y set y.state='2' where y.yaoyueid in (?)"; getHibernateTemplate().bulkUpdate(queryString, updateIds.toArray());*/ getHibernateTemplate().execute(new HibernateCallback(){ final String hql="update Yaoyuepub y set y.state=2 where yaoyueid in (:yaoyueid)"; public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query=session.createQuery(hql); query.setParameterList("yaoyueid", updateIds); query.executeUpdate(); return null; } } ); } catch (Exception e) { e.printStackTrace(); throw new DaoException(this.getClassName()+e.getMessage()); } } [/code] 这个方法是把所有的要改的ID都一次性更新调,我是不想执行多条sql,在Manager中调用这个方法事务就起不了作用,还有一个方法,就是普通的更新对象 [code="java"] public void update(T t) throws DaoException { try { getHibernateTemplate().update(t); } catch (Exception e) { throw new DaoException(getClassName() + " update exception...",e); } } [/code] 要是把刚才Manager中调用改成循环执行下面的方法一个一个对象,就是有事务的,所以调用都一样,更类的内部调用应给没有关系的,我认为不管是query.executeUpdate还是spring自己提供的bulkUpdate这两个方法都是要写sql的,目的是满足批量更新和更大的灵活性,但是事务就不行了,我认为肯定可以让声明式事务支持这两个方法,就是不知道怎么配置一下,你可以自己在代码中分别做个例子试试,看看是不是用批量更新事务就控制不了了, 这就是我的理解,还请多多指教,谢谢诶!!! [b]问题补充:[/b] 我测试过了,以为可以了,但是还是不行,下面是我调用的一小部分代码 [code="java"] public void runThread() { Set<String> updateIds = new HashSet<String>(); for (Yaoyueyingyue yaoyueyingyue : yaoyueyingyues) { updateIds.add(yaoyueyingyue.getYaoyueid()); } if (updateIds.size() > 0) { yaoyuepubDao.updateByIds(updateIds); if(true) throw new RuntimeException("AAAAAAAAAAAAAAAAAAAAAAAAA"); yaoyueyingyueDao.updateByIds(updateIds); } [/code] 上面是我Manager中Spring任务调度自动执行的方法的一小部分,我中间估计抛出了异常,但是yaoyuepubDao数据库中都更新了,事务不起作用,我估计其实就是和bulkUpdate方法一样,只要这个方法能用事务控制了的话,应该没问题了 [b]问题补充:[/b] 下面是我在网上拷贝的--------------------------------   Spring的HibernateTemplate提供了Hibernate的完美封装,即通过匿名类实现回调,来保证Session的自动资源管理和事务的管理。其中核心方法是:   java代码: HibernateTemplate.execute(new HibernateCallback() {  public Object doInHibernate(Session session) throws HibernateException {   ....  } }   回调方法提供了session作为参数,有了session,就可以自由的使用Hibernate API编程了。使用了spring的之后,代码修改如下:   web层代码:   java代码: DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Department.class); detachedCriteria.createAlias("employees", "e").add(Restrictions.eq("name", "department")).add(Restrictions.gt(("e.age"), new Integer(20))); departmentManager.findByCriteria(detachedCriteria);   构造detachedCriteria,作为参数传递给departmentManager   业务层代码使用spring,DepartmentManager的findByCriteria如下:   java代码: public List findByCriteria(final DetachedCriteria detachedCriteria) {  return (List) getHibernateTemplate().execute(new HibernateCallback() {   public Object doInHibernate(Session session) throws HibernateException {    Criteria criteria = detachedCriteria.getExecutableCriteria(session);    return criteria.list();   }  }); }   实际上也就是:   java代码: Criteria criteria = detachedCriteria.getExecutableCriteria(session); return criteria.list();   而已   但是该程序代码执行,会抛出强制类型转换异常!   我跟踪了一下spring和Hibernate源代码,原因如下:   spring的HibernateTemplate的execute方法提供的回调接口具有Session作为参数,但是实际上,默认情况下,HibernateTemplate传递给回调接口的session并不是org.hibernate.impl.SessionImpl类,而是SessionImpl类的一个Proxy类。之所以替换成为一个Proxy类,HibernateTemplate的注释说明,Proxy提供了一些额外的功能,包括自动设置Cachable,Transaction的超时时间,Session资源的更积极的关闭等等。   java代码: private boolean exposeNativeSession = false; ...   execute方法内部: Session sessionToExpose = (exposeNativeSession ? session : createSessionProxy(session));   但是遗憾的是,Hibernate的DetachedCriteria的setExecutableCriteria方法却要求将session参数强制转为SessionImpl,但是spring传过来的却是一个Proxy类,因此就报错了。   java代码: public Criteria getExecutableCriteria(Session session) {  impl.setSession( (SessionImpl) session ); // 要求SessionImpl,Spring传递的是Proxy  return impl; }   解决方法,禁止Spring的HibernateTemplate传递Proxy类,强制要求它传递真实的SessionImpl类,即给exexute方法增加一个参数,提供参数为true,如下:   java代码: public List findByCriteria(final DetachedCriteria detachedCriteria) {  return (List) getHibernateTemplate().execute(new HibernateCallback() {   public Object doInHibernate(Session session) throws HibernateException {    Criteria criteria = detachedCriteria.getExecutableCriteria(session);    return criteria.list();   }  }, true); } [b]问题补充:[/b] bulkUpdate这个方法按你给的源码,那我是用错了,但是你所说的我的模拟异常不再AOP的事务之内,我就不同意你的观点了,[code="java"] if (updateIds.size() > 0) { yaoyuepubDao.updateByIds(updateIds); // 事务开启 执行updateByIds 事务提交 if(true) throw new RuntimeException("AAAAAAAAAAAAAAAAAAAAAAAAA"); yaoyueyingyueDao.updateByIds(updateIds); // 事务开启 执行updateByIds 事务提交 } [/code] 我这段代码是两个Dao的操作,而这两个Dao的操作是被封装在一个Manger中的方法中的,Manager的每个方法都是有事务的,在操作玩第一个Dao后抛出一个RunTime异常,这时候第一个Dao操作已经执行了,这时候事务应该回滚的,不应该去更新的第一个Dao的操作,Manager中本来就业务层,中间有好多的Dao操作,事务应该控制这些Dao要不都提交,要不都回滚,你说呢,而你说的在11-12行之间加异常,那在一个Dao中,再说的的Dao是没有配事务的,又何谈回滚呢,要是把我上面两个Dao操作改成普通的对象更新,是可以回滚的,这个我肯定 比如这样 [code="java"] yaoyuepubDao.update(yaoyuepub); if(true) throw new RuntimeException("AAAAAAAAAAAAAAAAAAAAAAAAA"); yaoyueyingyueDao.update(yaoyueyingyue); [/code] 这个时候如果抛出异常,yaoyuepub是不会更新到数据库的,会回滚的,所以我总结就是executeUpdate(sql)这个方法我们直接sql,和操作对象是不一样的的,具体我也没有研究 [b]问题补充:[/b] [code="java"] public void updateByIds(final Set<String> updateIds)throws DaoException{ try { getHibernateTemplate().execute(new HibernateCallback(){ final String hql="update Yaoyuepub y set y.state=2 where yaoyueid in (:yaoyueid)"; public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query=session.createQuery(hql); query.setParameterList("yaoyueid", updateIds); query.executeUpdate(); return null; } } , true); } catch (Exception e) { e.printStackTrace(); throw new DaoException(this.getClassName()+e.getMessage()); } } [/code] 把上面的updateIds方法改成: [code="java"] public void updateByIds(final Set<String> updateIds)throws DaoException{ try { DetachedCriteria dc=DetachedCriteria.forClass(Yaoyuepub.class); dc.add(Restrictions.in("yaoyueid", updateIds)); List<Yaoyuepub> yaoyuepubs=select(dc); for(Yaoyuepub y:yaoyuepubs){ update(y); } } catch (Exception e) { e.printStackTrace(); throw new DaoException(this.getClassName()+e.getMessage()); } } [/code] 所有的调用都不变,spring事务就起作用了,说明自己createQuery然后executeUpdate是不被事务管理的,后其他都没有关系

ibatis+spring mvc事务不能回滚

<div class="iteye-blog-content-contain" style="font-size: 14px;"> <p>最近才接触spring MVC和ibates,现在我需要配置事务回滚,但是倒腾了一天还是不行,熟悉的朋友帮忙看看: applicationContext.xml文件配置:</p> <p> </p> <pre name="code" class="java">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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: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-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd" default-autowire="byName"&gt; &lt;context:component-scan base-package="com.suneee"&gt; &lt;context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/&gt; &lt;/context:component-scan&gt; &lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;property name="location"&gt; &lt;value&gt;classpath:com/suneee/config/mysql/jdbc.properties&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt; &lt;property name="driverClassName" value="${db.driverClassName}"/&gt; &lt;property name="url" value="${db.url}"/&gt; &lt;property name="username" value="${db.username}"/&gt; &lt;property name="password" value="${db.password}"/&gt; &lt;/bean&gt; &lt;!-- 配置数据源 --&gt; &lt;bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"&gt; &lt;property name="dataSource" ref="dataSource"/&gt; &lt;property name="configLocation"&gt; &lt;value&gt;classpath:com/suneee/config/ibatis/SqlMapConfig.xml&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- 配置事务管理器 --&gt; &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;/bean&gt; &lt;!-- 配置哪些类的方法需要进行事务管理 proxy-target-class="true" --&gt; &lt;aop:config &gt; &lt;aop:pointcut id="crudMethos" expression="execution(* com.suneee.service.*.*(..))"/&gt; &lt;aop:advisor advice-ref="txAdvice" pointcut-ref="crudMethos" /&gt; &lt;/aop:config&gt; &lt;!--配置哪些方法,什么情况下需要回滚--&gt; &lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt; &lt;tx:attributes&gt; &lt;tx:method name="insert*" propagation="REQUIRED" rollback-for="java.lang.Exception"/&gt; &lt;tx:method name="delete*" propagation="REQUIRED" rollback-for="java.lang.Exception"/&gt; &lt;tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Exception"/&gt; &lt;!-- &lt;tx:method name="*" propagation="REQUIRED" read-only="true"/&gt; --&gt; &lt;!-- 除了上面标识的方法,其他方法全是只读方法 --&gt; &lt;/tx:attributes&gt; &lt;/tx:advice&gt; &lt;/beans&gt;</pre> <p> </p> <p> </p> <p>springMVC.XML文件内容如下:</p> <p> </p> <pre name="code" class="java">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" default-autowire="byName"&gt; &lt;!-- 自动扫描的包名 --&gt; &lt;context:component-scan base-package="com.suneee"&gt; &lt;context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/&gt; &lt;/context:component-scan&gt; &lt;!-- 视图解释类 --&gt; &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix" value="/WEB-INF/jsp/"&gt;&lt;/property&gt; &lt;property name="suffix" value=".jsp"&gt;&lt;/property&gt; &lt;/bean&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt; &lt;/bean&gt; &lt;!-- 拦截器 &lt;mvc:interceptors&gt; &lt;mvc:interceptor&gt; &lt;mvc:mapping path="/*.do"/&gt; &lt;bean class="com.suneee.interceptor.MyInterceptor"&gt;&lt;/bean&gt; &lt;/mvc:interceptor&gt; &lt;/mvc:interceptors&gt; --&gt; &lt;/beans&gt;</pre> <p> </p> <p> </p> <p>UserService.java内容如下:</p> <p> </p> <pre name="code" class="java">package com.suneee.service.impl; import java.util.List; import org.springframework.stereotype.Service; import com.suneee.bean.User; import com.suneee.service.IUserService; import com.suneee.service.base.BaseService; @Service("userService") public class UserService extends BaseService&lt;User&gt; implements IUserService{ @Override public List&lt;User&gt; findUser(User user) { return queryForList("user_queryAll",user); } @Override public User insert(User user){ insert("user_insert",user); user = null;//故意设置为null,抛出异常 insert("user_inserts",user); return user; } } </pre> <p> </p> <p> </p> <p>BaseService.java文件如下:</p> <pre name="code" class="java">package com.suneee.service.base; import java.sql.SQLException; import java.util.List; import org.springframework.orm.ibatis.SqlMapClientTemplate; public class BaseService&lt;T&gt; extends SqlMapClientTemplate{ public static final int PAGE_SIZE = 15; public Object insert(String sqlId,Object baseClass){ Object baseClassResult = null; try { baseClassResult = (Object) super.getSqlMapClient().insert(sqlId,baseClass); } catch (SQLException e) { e.printStackTrace(); } return baseClassResult; } public Object queryForObject(String sqlId,Object baseClass){ Object baseClassResult = null; try { baseClassResult = (Object) super.getSqlMapClient().queryForObject(sqlId,baseClass); } catch (SQLException e) { e.printStackTrace(); } return baseClassResult; } public Integer delete(String sqlId,Integer id){ Integer number = null; try { number = super.getSqlMapClient().delete(sqlId, id); } catch (SQLException e) { e.printStackTrace(); } return number; } public Integer deleteByObject(String sqlId,Object obj){ Integer number = null; try { number = super.getSqlMapClient().delete(sqlId, obj); } catch (SQLException e) { e.printStackTrace(); } return number; } public Object queryById(String sqlId,Integer id){ Object baseClassResult = null; try { baseClassResult = (Object) super.getSqlMapClient().queryForObject(sqlId,id); } catch (SQLException e) { e.printStackTrace(); } return baseClassResult; } public List&lt;Object&gt; queryListByPage(String sqlId,Object obj){ List&lt;Object&gt; list = null; try { list = (List&lt;Object&gt;) super.getSqlMapClient().queryForList(sqlId, obj); } catch (SQLException e) { e.printStackTrace(); } return list; } public List&lt;Object&gt; queryListNoPage(String sqlId,Object obj){ List&lt;Object&gt; list = null; try { list = (List&lt;Object&gt;) super.getSqlMapClient().queryForList(sqlId, obj); } catch (SQLException e) { e.printStackTrace(); } return list; } public int update(String sqlId,Object obj){ Integer number = null; try { number = super.getSqlMapClient().update(sqlId, obj); } catch (SQLException e) { e.printStackTrace(); } return number; } //批量入库 public boolean insertBatch(String sqlId,List list){ Object obj = null; try { super.getSqlMapClient().startBatch(); for(int i=0; i&lt;list.size(); i++){ obj = list.get(i); super.getSqlMapClient().insert(sqlId,obj); } super.getSqlMapClient().executeBatch(); return true; } catch (SQLException e) { e.printStackTrace(); return false; } } public int getCount(String sqlId){ Integer i = null; try { i = (Integer) super.getSqlMapClient().queryForObject(sqlId); } catch (SQLException e) { e.printStackTrace(); } return i; } }</pre> <p> </p> <p> </p> <p>以上就是我项目各个地方的代码,第二个插入数据方法我故意设置为null,执行报错,但是第一个插入数据方法执行了数据插入,没有回滚,怎样才能回滚啊,声明式的事务配置有错还是什么原因,熟悉的兄弟看看,困扰了我一天多了</p> </div>

springBoot shiro 中 realm中注入service 使事务失效问题。

springBoot shiro 中 realm中注入service 使得 service的事务失效,如何解决。 在shiro的userRealm中 注入service时,导致注入的service没有事务(不会创建代理对象)。 ![图片说明](https://img-ask.csdn.net/upload/201805/18/1526636844_420952.png) ![图片说明](https://img-ask.csdn.net/upload/201805/18/1526636878_959306.png) 正常有事务的service 都应该是CGLI代理对象的。 应该怎么解决呢. 除了把 service改为dao,我需要事务

spring2.5事务注解

用到的是spring2.5的注解方式配置事务。 在接口中加入@Transactional这个就会报错,否则正常。 配置文件。 [code="java"]<?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:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" 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="db-properties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:ignoreUnresolvablePlaceholders="true"> <property name="locations"> <list> <value>classpath:DataBase.properties </value> </list> </property> </bean> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- 配置同一个数据源 --> <bean id="daoTemplate" abstract="true" lazy-init="true"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>${db.driver}</value> </property> <property name="url"> <value>${db.url}</value> </property> <property name="username"> <value>${db.username}</value> </property> <property name="password"> <value>${db.password}</value> </property> <property name="initialSize"> <value>${db.pool.initial}</value> </property> <property name="maxActive"> <value>${db.pool.max}</value> </property> <property name="defaultAutoCommit" value="false" /> </bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" /> <bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <property name="corePoolSize" value="2" /> <property name="keepAliveSeconds" value="200" /> <property name="maxPoolSize" value="10" /> <property name="queueCapacity" value="60" /> </bean> <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> </bean> </beans>[/code] 接口代码: [code="java"] import javax.jws.WebService; import javax.ws.rs.core.Response; import org.springframework.transaction.annotation.Transactional; import com.sns.bestv.entity.VisFclass; import com.sns.bestv.service.impl.VisFclassServiceImpl.Fclasses; @WebService @Transactional public interface VisFclassService { Response save(VisFclass fclass); Response delete(String app_key,int cid,String groupsids); Response update(VisFclass fclass); Fclasses get(String app_key,int cid); } [/code] 启动时候控制台错误信息: [code="java"] 2009-9-1 20:57:07 org.apache.catalina.core.AprLifecycleListener init 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: E:\java\jdk1.6.0_13\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;E:\java\jdk1.6.0_13\jre\bin;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Java\jdk1.6.0_13\BIN;C:\Program Files\Common Files\Adobe\AGL;;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\TortoiseSVN\bin;D:\;C:\Program Files\MySQL\MySQL Server 5.0\bin;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;d:\Program Files\SSH Secure Shell;C:\Program Files\SSH Communications Security\SSH Secure Shell 2009-9-1 20:57:07 org.apache.coyote.http11.Http11Protocol init 信息: Initializing Coyote HTTP/1.1 on http-8081 2009-9-1 20:57:07 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 763 ms 2009-9-1 20:57:07 org.apache.catalina.core.StandardService start 信息: Starting service Catalina 2009-9-1 20:57:07 org.apache.catalina.core.StandardEngine start 信息: Starting Servlet Engine: Apache Tomcat/6.0.18 log4j:ERROR Parsing error on line 30 and column 23 log4j:ERROR The content of element type "log4j:configuration" must match "(renderer*,appender*,(category|logger)*,root?,categoryFactory?)". 2009-9-1 20:57:08 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext 20:57:08,359 INFO org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:189): Root WebApplicationContext: initialization started 20:57:08,437 INFO org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:411): Refreshing org.springframework.web.context.support.XmlWebApplicationContext@db95a1: display name [Root WebApplicationContext]; startup date [Tue Sep 01 20:57:08 CST 2009]; root of context hierarchy 20:57:08,609 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323): Loading XML bean definitions from class path resource [applicationContext.xml] 20:57:08,937 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323): Loading XML bean definitions from class path resource [serviceContext.xml] 20:57:09,000 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323): Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml] 20:57:09,046 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323): Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-soap.xml] 20:57:09,093 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323): Loading XML bean definitions from class path resource [META-INF/cxf/cxf-servlet.xml] 20:57:09,187 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:323): Loading XML bean definitions from class path resource [META-INF/cxf/cxf-extension-jaxrs-binding.xml] 20:57:09,296 INFO org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:426): Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@db95a1]: org.springframework.beans.factory.support.DefaultListableBeanFactory@138847d 20:57:09,671 INFO org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:178): Loading properties file from class path resource [DataBase.properties] 20:57:10,000 INFO org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:414): Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@138847d: defining beans [db-properties,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,daoTemplate,dataSource,transactionManager,userDao,customerDao,custUserDao,aipUsersDao,aipLogDao,postDao,friendDao,messageDao,fclassDao,userClassDao,customizeDao,threadPoolTaskExecutor,transactionTemplate,cxf,org.apache.cxf.bus.spring.BusApplicationListener,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.transport.servlet.ServletTransportFactory,org.apache.cxf.jaxrs.JAXRSBindingFactory,userServices,profileService,postService,friendService,messageService,groupService,custermerService,customizeService,userServices_wa]; root of factory hierarchy 20:57:10,500 INFO org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.initialize(ThreadPoolTaskExecutor.java:250): Initializing ThreadPoolExecutor 'threadPoolTaskExecutor' 2009-9-1 20:57:12 org.apache.cxf.jaxrs.utils.InjectionUtils reportServerError 严重: Method setMessageContext injection failure 20:57:12,968 INFO org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:421): Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@138847d: defining beans [db-properties,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,daoTemplate,dataSource,transactionManager,userDao,customerDao,custUserDao,aipUsersDao,aipLogDao,postDao,friendDao,messageDao,fclassDao,userClassDao,customizeDao,threadPoolTaskExecutor,transactionTemplate,cxf,org.apache.cxf.bus.spring.BusApplicationListener,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.transport.servlet.ServletTransportFactory,org.apache.cxf.jaxrs.JAXRSBindingFactory,userServices,profileService,postService,friendService,messageService,groupService,custermerService,customizeService,userServices_wa]; root of factory hierarchy 20:57:12,984 INFO org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.shutdown(ThreadPoolTaskExecutor.java:349): Shutting down ThreadPoolExecutor 'threadPoolTaskExecutor' 20:57:12,984 ERROR org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215): Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServices_wa': Invocation of init method failed; nested exception is org.apache.cxf.service.factory.ServiceConstructionException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardHost.start(StandardHost.java:719) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:516) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:578) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) Caused by: org.apache.cxf.service.factory.ServiceConstructionException at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) ... 30 more Caused by: javax.ws.rs.WebApplicationException at org.apache.cxf.jaxrs.utils.InjectionUtils.reportServerError(InjectionUtils.java:277) at org.apache.cxf.jaxrs.utils.InjectionUtils.injectThroughMethod(InjectionUtils.java:190) at org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxies(InjectionUtils.java:656) at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:180) at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:201) at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:81) ... 37 more 2009-9-1 20:57:13 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServices_wa': Invocation of init method failed; nested exception is org.apache.cxf.service.factory.ServiceConstructionException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardHost.start(StandardHost.java:719) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:516) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:578) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) Caused by: org.apache.cxf.service.factory.ServiceConstructionException at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) ... 30 more Caused by: javax.ws.rs.WebApplicationException at org.apache.cxf.jaxrs.utils.InjectionUtils.reportServerError(InjectionUtils.java:277) at org.apache.cxf.jaxrs.utils.InjectionUtils.injectThroughMethod(InjectionUtils.java:190) at org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxies(InjectionUtils.java:656) at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactoryBean.java:180) at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAXRSServerFactoryBean.java:201) at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:81) ... 37 more 2009-9-1 20:57:13 org.apache.catalina.core.StandardContext start 严重: Error listenerStart 2009-9-1 20:57:13 org.apache.catalina.core.StandardContext start 严重: Context [] startup failed due to previous errors 2009-9-1 20:57:13 org.apache.catalina.core.ApplicationContext log 信息: Closing Spring root WebApplicationContext 2009-9-1 20:57:13 org.apache.coyote.http11.Http11Protocol start 信息: Starting Coyote HTTP/1.1 on http-8081 2009-9-1 20:57:13 org.apache.jk.common.ChannelSocket init 信息: JK: ajp13 listening on /0.0.0.0:9009 2009-9-1 20:57:13 org.apache.jk.server.JkMain start 信息: Jk running ID=0 time=0/47 config=null 2009-9-1 20:57:13 org.apache.catalina.startup.Catalina start 信息: Server startup in 6270 ms [/code] [b]问题补充:[/b] 1:@Transactional 不是说用注解就得用接口吗?你说的加到实现类上我也试了一样的错误。 2:[code="java"]<bean id="threadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <property name="corePoolSize" value="2" /> <property name="keepAliveSeconds" value="200" /> <property name="maxPoolSize" value="10" /> <property name="queueCapacity" value="60" /> </bean> [/code] 这是连接池的东西。 3: <!-- 定义切入点,引用事务通知 --> [code="java"]<aop:config proxy-target-class="true"> <aop:advisor advice-ref="txAdvice" pointcut="execution (* com.mobile.dao.*.*(..))"/>[/code] </aop:config> 这种方式我试过了。也会出错。 [b]4:其二,既然你要用注解的方式,那么你就要在你的项目中,加入这两个jar包:aspectjweaver.jar aspectjrt.jar 我好像没加这两个包。我加加试试。[/b] 5:配置文件哪里有问题?如果我不在接口或类上加@Transactional 就是完全正确的运行。 谢谢!请帮忙! [b]问题补充:[/b] [b]再补充:两个包我加了,还是一样的错误。而且那两个包是aop才需要的吧?[/b] [b]问题补充:[/b] [b][color=darkred]yangtao309[/color][/b] 按照你说的把那个多余的连接池delete了。程序不会出错了。 但是不会回滚事务? 那我另问一下:[color=blue]我把@Transactional(readOnly=false) public Response addCustomer(VisCustomer cut) 放在一个接口的实现类的方法上面,那是不是就说我这个方法体都具有一个相同的事务呢?只要其中一个地方出错整个方法都执行失败? 因为我这个方法内不止使用了一个dao的一个方法,有多个方法。比如我现在有 table1,table1-2(关系表),table2 我现在要操作table1,给其insert ,insert之后要向 table1-2中添加一条数据,这时我添加table1-2时出错了,那么我操作table1的数据可以回滚吗? [/color] [b]问题补充:[/b] [b]我添加table1-2时并没有异常,是在数据库中被回滚的,程序中执行是正确的。这样能把它在程序中就回滚了吗?我正在看spring2.5的开发参考手册,其中rollbackForClassname 是定义一组类的名字,必须是Throwable的子类,遇到时必须回滚。如果我产生不了异常不就是说还是回滚不了?[/b] [b]问题补充:[/b] [quote]@Transactional(readOnly=false,rollbackFor = Throwable.class)[/quote] 不能回滚事务。肯定还有地方不对。但是配置我想是没问题了。看了api现在完全按照上面来了。非常非常感谢[color=olive]yangtao309 [/color]

eclipse中springboot在类中使用@Transactional和@Async后,打断点进行debug就会提示missing line number?

项目使用springboot开发,有几个类中使用了@Transactional事物回滚注解或者是@Async异步任务。 后面要调试的时候在类中加断点,debug一启动就会报错。![图片说明](https://img-ask.csdn.net/upload/201911/15/1573803462_938332.png) 其他类中的断点都能正常进入,只有这些类的断点会报这个错误,如果跟进去的话就会进到spring框架的一个aop类里面 ![图片说明](https://img-ask.csdn.net/upload/201911/15/1573803645_944062.png) 急死了,现在异步任务功能无效,又调试不了!!! 网上找的各种方法都不行,搜又搜不到跟我同样问题的,请问有朋友遇到过相同的问题吗???很急!!重赏!!!

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

点沙成金:英特尔芯片制造全过程揭密

“亚马逊丛林里的蝴蝶扇动几下翅膀就可能引起两周后美国德州的一次飓风……” 这句人人皆知的话最初用来描述非线性系统中微小参数的变化所引起的系统极大变化。 而在更长的时间尺度内,我们所生活的这个世界就是这样一个异常复杂的非线性系统…… 水泥、穹顶、透视——关于时间与技艺的蝴蝶效应 公元前3000年,古埃及人将尼罗河中挖出的泥浆与纳特龙盐湖中的矿物盐混合,再掺入煅烧石灰石制成的石灰,由此得来了人...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

C++11:一些微小的变化(新的数据类型、template表达式内的空格、nullptr、std::nullptr_t)

本文介绍一些C++的两个新特性,它们虽然微小,但对你的编程十分重要 一、Template表达式内的空格 C++11标准之前建议在“在两个template表达式的闭符之间放一个空格”的要求已经过时了 例如: vector&lt;list&lt;int&gt; &gt;; //C++11之前 vector&lt;list&lt;int&gt;&gt;; //C++11 二、nullptr ...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

深入剖析Springboot启动原理的底层源码,再也不怕面试官问了!

大家现在应该都对Springboot很熟悉,但是你对他的启动原理了解吗?

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

【阿里P6面经】二本,curd两年,疯狂复习,拿下阿里offer

二本的读者,在老东家不断学习,最后逆袭

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

微软为一人收购一公司?破解索尼程序、写黑客小说,看他彪悍的程序人生!...

作者 | 伍杏玲出品 | CSDN(ID:CSDNnews)格子衬衫、常掉发、双肩包、修电脑、加班多……这些似乎成了大众给程序员的固定标签。近几年流行的“跨界风”开始刷新人们对程序员的...

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

我说我懂多线程,面试官立马给我发了offer

不小心拿了几个offer,有点烦

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

立即提问
相关内容推荐