atomikos分布式事务问题

2015-11-05 11:38:14.957 [main] ERROR
java.sql.Connection[JakartaCommonsLoggingImpl.java:19] - Error calling Connection.prepareStatement:
com.atomikos.datasource.ResourceException: XA resource 'ds2': resume for XID '636F6D2E746C772E62706D2E656E6769
6E652E61746F6D696B6F732E737072696E672E6A6462632E746D30303030313030303134:636F6D2E746C772E62706D2E656E67696E652
E61746F6D696B6F732E737072696E672E6A6462632E746D33' raised -8: the supplied XID already exists in this XA resou
rce
at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:434) ~[transactions-jta
-3.9.1.jar:na]
at com.atomikos.datasource.xa.session.BranchEnlistedStateHandler.(BranchEnlistedStateHandler.java:59) ~
[transactions-jta-3.9.1.jar:na]
at com.atomikos.datasource.xa.session.NotInBranchStateHandler.checkEnlistBeforeUse(NotInBranchStateHandler.ja
va:64) ~[transactions-jta-3.9.1.jar:na]
at com.atomikos.datasource.xa.session.TransactionContext.checkEnlistBeforeUse(TransactionContext.java:88) ~[t
ransactions-jta-3.9.1.jar:na]
at com.atomikos.datasource.xa.session.SessionHandleState.notifyBeforeUse(SessionHandleState.java:179) ~[trans
actions-jta-3.9.1.jar:na]
at com.atomikos.jdbc.AtomikosConnectionProxy.enlist(AtomikosConnectionProxy.java:223) ~[transactions-jdbc-3.9
.1.jar:na]
at com.atomikos.jdbc.AtomikosConnectionProxy.invoke(AtomikosConnectionProxy.java:142) ~[transactions-jdbc-3.9
.1.jar:na]
at com.sun.proxy.$Proxy7.prepareStatement(Unknown Source) ~[na:na]
at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_45]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_45]
at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invo
ke(TransactionAwareDataSourceProxy.java:239) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at com.sun.proxy.$Proxy4.prepareStatement(Unknown Source) ~[na:na]
at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_45]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_45]
at com.ibatis.common.jdbc.logging.ConnectionLogProxy.invoke(ConnectionLogProxy.java:53) ~[ibatis-sqlmap-2.3.0
.jar:na]
at com.sun.proxy.$Proxy5.prepareStatement(Unknown Source) [na:na]
at com.ibatis.sqlmap.engine.execution.SqlExecutor.prepareStatement(SqlExecutor.java:494) [ibatis-sqlmap-2.3.0
.jar:na]
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:76) [ibatis-sqlmap-2.3.0.jar
:na]
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUpdate(GeneralStatement.java:200) [i
batis-sqlmap-2.3.0.jar:na]
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:78) [ibati
s-sqlmap-2.3.0.jar:na]
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:447) [ibatis-sqlma
p-2.3.0.jar:na]
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82) [ibatis-sqlmap-2.3.0.jar
:na]
at org.springframework.orm.ibatis.SqlMapClientTemplate$8.doInSqlMapClient(SqlMapClientTemplate.java:369) [spr
ing-orm-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:203) [spring-orm-3.2
.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.orm.ibatis.SqlMapClientTemplate.insert(SqlMapClientTemplate.java:367) [spring-orm-3.2.
2.RELEASE.jar:3.2.2.RELEASE]

2个回答

(已经决解)
原因:是因为多次开启事务
在一个方法的被调用的时候开启了事务,在这个方法里面调用的另外一个方法,这个方法本身自己也开启了事务。

谢谢了。我也是这个问题呢。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
关于Java使用atomikos分布式事务问题
使用的ssm框架,管理事务出现异常: XML事务配置如下: <!-- 分布式事务 --> <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown" value="true"/> </bean> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> <property name="transactionTimeout" value="3"/> </bean> <!-- JTA事务管理器 --> <bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager" ref="atomikosTransactionManager"/> <property name="userTransaction" ref="atomikosUserTransaction"/> </bean> <!-- 基于注解的声明式事务 --> <tx:annotation-driven transaction-manager="springTransactionManager" /> tomcat一启动时,报 com.atomikos.icatch.jta.UserTransactionManager类找不到, 如果采用单元测试,分布式事务能正常使用。 听别人说tomcat好像不支持JTA管理,请问下tomcat该怎么配置?
Atomikos实现分布式事务管理如何提高性能
Spring+Hibernate+Atomikos多数据源分布式事务管理,性能低,耗时性长,请问有什么方法可以解决这个问题,求指教
atomikos 解决分布式事务报错,求大神~
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2d694821] 2019-05-05 16:05:24.561 WARN 12880 --- [nio-8080-exec-1] c.atomikos.jdbc.AbstractDataSourceBean : AtomikosDataSoureBean 'db2': poolSize equals default - this may cause performance problems! 2019-05-05 16:05:24.593 WARN 12880 --- [nio-8080-exec-1] com.alibaba.druid.pool.DruidDataSource : removeAbandoned is true, not use in productiion. 2019-05-05 16:05:25.899 INFO 12880 --- [nio-8080-exec-1] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited 2019-05-05 16:05:25.908 INFO 12880 --- [nio-8080-exec-1] c.a.d.xa.XATransactionalResource : db2: refreshed XAResource 2019-05-05 16:05:25.970 WARN 12880 --- [nio-8080-exec-1] c.a.r.xa.XaResourceRecoveryManager : Error while retrieving xids from resource - will retry later... com.mysql.cj.jdbc.MysqlXAException: XAER_RMERR: Fatal error occurred in the transaction branch - check your data for consistency at com.mysql.cj.jdbc.MysqlXAConnection.mapXAExceptionFromSQLException(MysqlXAConnection.java:333) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.mysql.cj.jdbc.MysqlXAConnection.recover(MysqlXAConnection.java:184) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.mysql.cj.jdbc.MysqlXAConnection.recover(MysqlXAConnection.java:112) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.atomikos.datasource.xa.RecoveryScan.recoverXids(RecoveryScan.java:32) ~[transactions-jta-4.0.6.jar:na] at com.atomikos.recovery.xa.XaResourceRecoveryManager.retrievePreparedXidsFromXaResource(XaResourceRecoveryManager.java:158) [transactions-jta-4.0.6.jar:na] at com.atomikos.recovery.xa.XaResourceRecoveryManager.recover(XaResourceRecoveryManager.java:67) [transactions-jta-4.0.6.jar:na] at com.atomikos.datasource.xa.XATransactionalResource.recover(XATransactionalResource.java:449) [transactions-jta-4.0.6.jar:na] at com.atomikos.datasource.xa.XATransactionalResource.setRecoveryService(XATransactionalResource.java:416) [transactions-jta-4.0.6.jar:na] at com.atomikos.icatch.config.Configuration.addResource(Configuration.java:249) [transactions-api-4.0.6.jar:na] at com.atomikos.jdbc.AtomikosDataSourceBean.doInit(AtomikosDataSourceBean.java:183) [transactions-jdbc-4.0.6.jar:na] at com.atomikos.jdbc.AbstractDataSourceBean.init(AbstractDataSourceBean.java:292) [transactions-jdbc-4.0.6.jar:na] at com.atomikos.jdbc.AbstractDataSourceBean.getConnection(AbstractDataSourceBean.java:343) [transactions-jdbc-4.0.6.jar:na] at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157) [spring-jdbc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115) [spring-jdbc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78) [spring-jdbc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82) [mybatis-spring-1.3.2.jar:1.3.2] at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68) [mybatis-spring-1.3.2.jar:1.3.2] at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:338) [mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84) [mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49) [mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) [mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) [mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198) [mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185) [mybatis-3.4.6.jar:3.4.6] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_102] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_102] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_102] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_102] at com.yintw.springboot.config.CustomSqlSessionTemplate$SqlSessionInterceptor.invoke(CustomSqlSessionTemplate.java:117) [classes/:na] at com.sun.proxy.$Proxy64.insert(Unknown Source) [na:na] at com.yintw.springboot.config.CustomSqlSessionTemplate.insert(CustomSqlSessionTemplate.java:231) [classes/:na] at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:58) [mybatis-3.4.6.jar:3.4.6] at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) [mybatis-3.4.6.jar:3.4.6] at com.sun.proxy.$Proxy66.insert(Unknown Source) [na:na] at com.yintw.springboot.dao.impl.TuserDaoImpl.insert(TuserDaoImpl.java:83) [classes/:na] at com.yintw.springboot.dao.impl.TuserDaoImpl$$FastClassBySpringCGLIB$$6f464830.invoke(<generated>) [classes/:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) [spring-core-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) [spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56) [spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:47) [spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) ~[spring-tx-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at com.yintw.springboot.dao.impl.TuserDaoImpl$$EnhancerBySpringCGLIB$$c2209d67.insert(<generated>) ~[classes/:na] at com.yintw.springboot.service.impl.ProgrammerServiceImpl.insert(ProgrammerServiceImpl.java:95) ~[classes/:na] at com.yintw.springboot.service.impl.ProgrammerServiceImpl$$FastClassBySpringCGLIB$$286d4e3f.invoke(<generated>) ~[classes/:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) [spring-core-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) [spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) ~[spring-tx-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-tx-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.1.4.RELEASE.jar:5.1.4.RELEASE] at com.yintw.springboot.service.impl.ProgrammerServiceImpl$$EnhancerBySpringCGLIB$$6ec96463.insert(<generated>) ~[classes/:na] at com.yintw.springboot.controller.ProgrammerController.insert(ProgrammerController.java:52) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_102] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_102] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_102] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_102] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.14.jar:9.0.14] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:124) ~[druid-1.1.16.jar:1.1.16] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_102] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_102] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.14.jar:9.0.14] at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_102] Caused by: java.sql.SQLException: XAER_RMERR: Fatal error occurred in the transaction branch - check your data for consistency at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.mysql.cj.jdbc.StatementImpl.executeQuery(StatementImpl.java:1247) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.mysql.cj.jdbc.MysqlXAConnection.recover(MysqlXAConnection.java:163) ~[mysql-connector-java-8.0.11.jar:8.0.11] ... 116 common frames omitted ![图片说明](https://img-ask.csdn.net/upload/201905/05/1557044056_5358.jpg)![图片说明](https://img-ask.csdn.net/upload/201905/05/1557044064_836340.jpg)
spring+hibernate+atomikos 实现JTA分布式事务时自定义事务隔离级别无效
因为需要对两个数据库同时操作并且放在同一个事务中,所以采用了atomikos去实现JTA分布式事务。数据库用的是SQL Server2014 . 现在的问题是,事务提交回滚,一切都正常,但是没有按照设定好的事务隔离级别给数据库表加锁。比如service中的save方法 设定的是SERIALIZABLE隔离级别,测试时查询数据库表隔离级别,并未按照预期加锁。 以下是配置文件,请大神给解惑一下。 ``` <?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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> <!-- 修改 --> <!-- 1.扫描包 --> <!--context:component-scan base-package=""></context:component-scan--> <!--context:component-scan base-package="wms.*"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan--> <context:component-scan base-package="com.baoJian.wmsBasic.*.dao"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/> </context:component-scan> <context:component-scan base-package="com.baoJian.wmsBasic.*.service"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/> </context:component-scan> <!-- 2.加载属性文件 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:jdbc.properties"></property> </bean> <!--develop开发环境配置,测试环境配置 对应web.xml中也有相关设置--> <!--beans profile="develop"> <context:property-placeholder location="classpath:jdbc.properties"/> </beans> <beans profile="product"> <context:property-placeholder location="classpath:jdbc_product.properties"/> </beans--> <beans> <!-- 修改 --> <!-- 3.配置数据库连接池 更改为JTA--> <bean class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close" id="dataSource"> <!-- Set unique name for this DataSource --> <property name="uniqueResourceName"><value>dataSource_main</value></property> <!-- Set XADatasource class name --> <property name="xaDataSourceClassName" value="com.microsoft.sqlserver.jdbc.SQLServerXADataSource" /> <property name="xaProperties"> <props> <prop key="URL">${jdbcUrl}</prop> </props> </property> <!-- set properties for datasource connection pool --> <property name="poolSize" value="3" /> <!-- timeout after 20000 seconds --> <property name="minPoolSize" value="3" /> <property name="maxPoolSize" value="6" /> <property name="borrowConnectionTimeout" value="60" /> <property name="reapTimeout"><value>300</value></property> <property name="loginTimeout" value="40" /> <property name="testQuery"> <value>select 1</value> </property> </bean> <bean class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close" id="dataSource_erp"> <!-- Set unique name for this DataSource --> <property name="uniqueResourceName"><value>dataSource_erp</value></property> <!-- Set XADatasource class name --> <property name="xaDataSourceClassName" value="oracle.jdbc.xa.client.OracleXADataSource" /> <property name="xaProperties"> <props> <!--prop key="URL">jdbc:oracle:thin:@erptest.baojian.com:1541:DEV2</prop--> <prop key="URL">${oraJdbcUrl}</prop> <prop key="user">${oraUser}</prop> <prop key="password">${oraPassword}</prop> </props> </property> <!-- set properties for datasource connection pool --> <property name="poolSize" value="3" /> <!-- timeout after 20000 seconds --> <property name="reapTimeout"><value>300</value></property> </bean> <!-- 修改 --> <!-- 4.Hibernate的相关信息 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="classpath:hibernate.cfg.xml"/> </bean> <bean id="sessionFactory_erp" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource_erp"></property> <property name="configLocation" value="classpath:hibernate_erp.cfg.xml"/> </bean> <!-- 分布式事务 --> <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown" value="true"/> </bean> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> <property name="transactionTimeout" value="50000"/> </bean> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager" ref="atomikosTransactionManager"/> <property name="userTransaction" ref="atomikosUserTransaction"/> <property name="allowCustomIsolationLevels" value="true"/> </bean> <!--<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> --> <!-- 6.开启事务注解 --> <!--tx:annotation-driven transaction-manager="transactionManager"/--> <tx:advice id="txAdvice" transaction-manager="transactionManager" > <tx:attributes> <!--init初始化操作 calculate计算类操作 save保存操作 remove删除操作 update更新操作--> <tx:method name="init*" propagation="REQUIRED" rollback-for="Exception"></tx:method> <tx:method name="calculate*" propagation="REQUIRED" rollback-for="Exception"></tx:method> <tx:method name="save*" propagation="REQUIRED" isolation="SERIALIZABLE" rollback-for="Exception"></tx:method> <tx:method name="*" read-only="true"></tx:method> </tx:attributes> </tx:advice> <!--定义哪些类的哪些方法参与事务 --> <aop:config> <!-- <aop:pointcut id="allManagerMethod" expression="execution(* com.baojian.demo.service.*.*(..))"/> --> <aop:pointcut id="allServiceMethod" expression="execution(* *..service.*.*(..))"/> <aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice"/> </aop:config> </beans> ``` 测试例子 server中的一个方法 ``` public void saveTestHeader() throws InventoryServiceException, ReceiptServiceException { System.out.println("------------------TransactionSynchronizationManager"+TransactionSynchronizationManager.getCurrentTransactionIsolationLevel()); //查询并锁定 TestHeader testHeader = this.testDao.findOneByHQL("from TestHeader where id=160"); Thread.sleep(30000); } ```
使用Atomikos做DB2的分布式事务,我使用的是谁的连接池?
数据库DB2 框架springboot+mybatis,使用Atomikos集成了分布式XA事务。 ``` @Bean(name = "TESTDataSource") public DataSource dataSourceCar(XFDataSourceProperties dataSourceProperties) { DB2XADataSource dbdataSource = new DB2XADataSource();//使用DB2的XADataSource dbdataSource.setDatabaseName("testdb"); dbdataSource.setUser("db2admin"); dbdataSource.setPassword("123456"); //DruidXADataSource dataSource = new DruidXADataSource(); BeanUtils.copyProperties(dataSourceProperties, dbdataSource); AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean(); xaDataSource.setXaDataSource(dbdataSource); xaDataSource.setUniqueResourceName("TESTDataSource"); return xaDataSource; } ``` 数据库连接池之前用的是Druid,但是Druid的XA不支持db2,所以使用了DB2的,但是我现在不知道我使用的连接池是哪一个了,是springboot默认的HikariCP,还是说会使用我在配置文件指定的spring.datasource.type. 同时数据库连接池的一些属性改怎样设置? 或者有没有其他更好的支持DB2的分布式事务方式? 求解?
atomikos jta事务异常
最近使用atomikos进行分布式事务开发,遇到以下问题:com.atomikos.datasource.ResourceException: XA resource 'ds': resume for XID '31302E3131362E3134302E3231352E746D313439373430373435373030313134323636:31302E3131362E3134302E3231352E746D353639303533' raised -9: the XA resource is currently involved in a local (non-XA) transaction。 这个异常是从一个hibernate查询中报出来的,不是每次查询都会报异常,偶尔会报,事务管理器使用的是JtaTransactionManager,基本代码如下: ``` @Service("groundQuartzMonitorBiz") @Transactional public class QuartzMonitorBiz extends BaseBiz implements IQuartzMonitorBiz { private @Autowired IQuartzMonitorDao quartzMonitorDao; @Override @Transactional(readOnly = true) public Map<?,?> loadQuartzMonitor(String jobCode) { if (jobCode == null || "".equals(jobCode.trim())) { return null; } List<Map<?,?>> rets = quartzMonitorDao.loadQuartzMonitor(jobCode); if (null == rets || rets.isEmpty()) { return null; } return rets.iterator().next(); } } ``` ``` @Repository("groundQuartzMonitorDao") public class QuartzMonitorDao extends CommonDao implements IQuartzMonitorDao { @Override @SuppressWarnings("unchecked") public List<Map<?, ?>> loadQuartzMonitor(String jobCode) { Query query = this.getCurrentSession().createSQLQuery( select id,job_code,startup_flg,cron_expression_flg,cron_expression,comments from ts_quartz_monitor t where t.job_code=:jobcode); query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); query.setString("jobcode", jobCode); return query.list(); } } ``` 哪位大神遇到过这种情况的请分享一下,不胜感激。
spring4事务afterCompletion方法中unbindResourceIfPossible但是报错无此方法
![a](https://img-ask.csdn.net/upload/201908/27/1566876168_287073.png)![图片说明](https://img-ask.csdn.net/upload/201908/27/1566876186_920156.jpg)有且仅有一个导入的对应jar,排除jar冲突,spring版本是4.3.7,事务是使用的atomikos分布式事务处理工具如下图![图片说明](https://img-ask.csdn.net/upload/201908/27/1566876491_656231.jpg) 请路过看到的大神帮忙看下解答下疑惑
Spring事务超时回滚问题,困扰两天了
项目用的是springmvc+spring+hibernate框架,采用atomikos分布式事务管理,现在存在一个问题 ,service层的一个方法saveZwzxProject调用另外一个方法createMaterial,这个createMaterial方法是处理附件上传的,项目的附件都是上传到mongodb,如果附件数量很多或者附件很大,会导致这个方法执行非常的慢,从而导致saveZwzxProject方法事务超时,回滚,有什么办法让这个方法永不超时呢![图片说明](https://img-ask.csdn.net/upload/201608/10/1470792129_156992.png) ![图片说明](https://img-ask.csdn.net/upload/201608/10/1470792145_999113.png)
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是不被事务管理的,后其他都没有关系
spring + hibernate +jta 事务不能回滚问题
由于在项目中 用到分布式事务 引用 http://momoko8443.iteye.com/blog/190994 的帖子 按照上面的配置事务不能回滚 ,对于单个数据库也是一样 问题困扰了我三天了 每天晚上查资料查到晚上3点,求各位帮帮我,先谢了 代码及其配置 如下 配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="idcJDBC" class="com.atomikos.jdbc.SimpleDataSourceBean"> <property name="uniqueResourceName"><value>db_idcbase</value></property> <property name="xaDataSourceClassName"><value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value></property> <property name="xaDataSourceProperties"> <value>URL=jdbc:mysql://127.0.0.1:3306/db_idcbase?useUnicode=true&characterEncoding=gb2312;user=root;password=admin</value> </property> <property name="exclusiveConnectionMode"><value>true</value></property> <property name="connectionPoolSize"><value>3</value></property> <property name="validatingQuery"><value>SELECT 1</value></property> </bean> <!--sessionFactoryIdc --> <bean id="sessionFactoryIdc" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="idcJDBC" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value> com/yiwei/hibernate/bean/TblReportHosts.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblRuleUrls.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblRuleIps.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblRuleTcps.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblRuleUdps.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblReportUrls.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblReportKeys.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblReportTcps.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblReportUdps.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblRuleKeys.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblReportProbes.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblReportVhosts.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblRuleConfs.hbm.xml </value> <value> com/yiwei/hibernate/bean/TblRuleType.hbm.xml </value> </list> </property></bean> <!--isp鏁版嵁搴? --> <bean id="ispJDBC" class="com.atomikos.jdbc.SimpleDataSourceBean"> <property name="uniqueResourceName"><value>isp</value></property> <property name="xaDataSourceClassName"><value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value></property> <property name="xaDataSourceProperties"> <value>URL=jdbc:mysql://127.0.0.1:3306/isp?useUnicode=true&characterEncoding=gb2312;user=root;password=admin</value> </property> <property name="exclusiveConnectionMode"><value>true</value></property> <property name="connectionPoolSize"><value>3</value></property> <property name="validatingQuery"><value>SELECT 1</value></property> </bean> <bean id="sessionFactoryIsp" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="ispJDBC"/> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value> com/yiwei/hibernate/bean/Carrier.hbm.xml </value> <value> com/yiwei/hibernate/bean/UbietyDrawer.hbm.xml </value> <value>com/yiwei/hibernate/bean/UbietyRoom.hbm.xml</value> <value>com/yiwei/hibernate/bean/User.hbm.xml</value> <value>com/yiwei/hibernate/bean/Host.hbm.xml</value> <value>com/yiwei/hibernate/bean/Proxyer.hbm.xml</value> <value>com/yiwei/hibernate/bean/Region.hbm.xml</value> <value>com/yiwei/hibernate/bean/Role.hbm.xml</value> <value> com/yiwei/hibernate/bean/SysPrincipal.hbm.xml </value> <value> com/yiwei/hibernate/bean/SysRolePrincipal.hbm.xml </value> <value> com/yiwei/hibernate/bean/SysUserRole.hbm.xml </value> <value>com/yiwei/hibernate/bean/Log.hbm.xml</value> <value>com/yiwei/hibernate/bean/Vhost.hbm.xml</value> <value>com/yiwei/hibernate/bean/TblProxyerService.hbm.xml</value> </list> </property></bean> <!-- jta事务 --> <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</value></property> </bean> <bean id="hibernateTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager"> <ref local="atomikosTransactionManager"/> </property> <property name="userTransaction"> <ref local="atomikosUserTransaction"/> </property> </bean> <!-- IspDAO <bean id="IspDAO" class="com.yiwei.hibernate.bean.TblIspDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryPsb" /> </property> </bean> <bean id="ispServiceTarget" class="com.yiwei.business.service.IspServiceImp"> <property name="ispDAO"> <ref bean="IspDAO"/> </property> </bean> <bean id="ispService" parent="Psb.baseTxProxy"> <property name="target"> <ref bean="ispServiceTarget"/> </property> </bean> --> <!-- UbietyRoomDAO --> <bean id="UbietyRoomDAO" class="com.yiwei.hibernate.bean.UbietyRoomDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp" /> </property> </bean> <bean id="ubietyRoomTarget" class="com.yiwei.business.service.UbietyRoomServiceImp"> <property name="ubietyRoomDAO"> <ref bean="UbietyRoomDAO" /> </property> </bean> <bean id="ubietyRoomService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="ubietyRoomTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED </prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- UbietyDrawerDAO --> <bean id="UbietyDrawerDAO" class="com.yiwei.hibernate.bean.UbietyDrawerDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp" /> </property> </bean> <bean id="ubietyDrawerTarget" class="com.yiwei.business.service.UbietyDrawerServiceImp"> <property name="ubietyDrawerDAO"> <ref bean="UbietyDrawerDAO" /> </property> </bean> <bean id="ubietyDrawerService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="ubietyDrawerTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- CarrierDAO --> <bean id="CarrierDAO" class="com.yiwei.hibernate.bean.CarrierDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp" /> </property> </bean> <bean id="carrierServiceTarget" class="com.yiwei.business.service.CarrierServiceImp"> <property name="carrierDAO"> <ref bean="CarrierDAO" /> </property> </bean> <bean id="carrierService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="carrierServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- HostDAO --> <bean id="HostDAO" class="com.yiwei.hibernate.bean.HostDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp" /> </property> </bean> <bean id="hostServiceTarget" class="com.yiwei.business.service.HostServiceImp"> <property name="hostDAO"> <ref bean="HostDAO" /> </property> <property name="reportHostsDAO"> <ref bean="TblReportHostsDAO" /> </property> <property name="ubietyRoomDAO"> <ref bean="UbietyRoomDAO" /> </property> <property name="ubietyDrawerDAO"> <ref bean="UbietyDrawerDAO" /> </property> <property name="proxyerDAO"> <ref bean="ProxyerDAO" /> </property> </bean> <bean id="hostService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="hostServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- UserDAO --> <bean id="UserDAO" class="com.yiwei.hibernate.bean.UserDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp" /> </property> </bean> <bean id="userServiceTarget" class="com.yiwei.business.service.UserServiceImp"> <property name="userDAO"> <ref bean="UserDAO" /> </property> <property name="sysPrincipalDAO"> <ref bean="SysPrincipalDAO" /> </property> <property name="sysRolePrincipalDAO"> <ref bean="SysRolePrincipalDAO" /> </property> </bean> <bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="userServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- TblReportHostsDAO --> <bean id="TblReportHostsDAO" class="com.yiwei.hibernate.bean.TblReportHostsDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc" /> </property> </bean> <bean id="reportHostsServiceTarget" class="com.yiwei.business.service.ReportHostsServiceImp"> <property name="reportHostsDAO"> <ref bean="TblReportHostsDAO" /> </property> </bean> <bean id="reportHostsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="reportHostsServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- ProxyerDAO --> <bean id="ProxyerDAO" class="com.yiwei.hibernate.bean.ProxyerDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp" /> </property> </bean> <bean id="proxyerServiceTarget" class="com.yiwei.business.service.ProxyerServiceImp"> <property name="proxyerDAO"> <ref bean="ProxyerDAO" /> </property> </bean> <bean id="proxyerService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="proxyerServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- RegionDAO --> <bean id="RegionDAO" class="com.yiwei.hibernate.bean.RegionDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp" /> </property> </bean> <!-- TblRuleUrlsDAO --> <bean id="TblRuleUrlsDAO" class="com.yiwei.hibernate.bean.TblRuleUrlsDAO"> <property name="sessionFactory"> <ref local="sessionFactoryIdc" /> </property> </bean> <bean id="ruleUrlsServiceTarget" class="com.yiwei.business.service.RuleUrlsServiceImp"> <property name="logDAO"> <ref local="LogDAO" /> </property> <property name="ruleConfsDAO"> <ref local="TblRuleConfsDAO" /> </property> <property name="ruleUrlsDAO"> <ref local="TblRuleUrlsDAO" /> </property> </bean> <bean id="ruleUrlsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref local="hibernateTransactionManager"/> </property> <property name="target"> <ref local="ruleUrlsServiceTarget"/> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- <bean id="ruleUrlsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="ruleUrlsServiceTarget" /> </property> </bean> TblRuleIpsDAO --> <bean id="TblRuleIpsDAO" class="com.yiwei.hibernate.bean.TblRuleIpsDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc" /> </property> </bean> <bean id="ruleIpsServiceTarget" class="com.yiwei.business.service.RuleIpsServiceImp"> <property name="ruleIpsDAO"> <ref bean="TblRuleIpsDAO" /> </property> <property name="logDAO"> <ref bean="LogDAO" /> </property> <property name="ruleConfsDAO"> <ref bean="TblRuleConfsDAO" /> </property> </bean> <bean id="ruleIpsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="ruleIpsServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- TblRuleTcpsDAO --> <bean id="TblRuleTcpsDAO" class="com.yiwei.hibernate.bean.TblRuleTcpsDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc" /> </property> </bean> <bean id="ruleTcpsServiceTarget" class="com.yiwei.business.service.RuleTcpsServiceImp"> <property name="ruleTcpsDAO"> <ref bean="TblRuleTcpsDAO" /> </property> <property name="logDAO"> <ref bean="LogDAO" /> </property> <property name="ruleConfsDAO"> <ref bean="TblRuleConfsDAO" /> </property> </bean> <bean id="ruleTcpsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="ruleTcpsServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- TblRuleUdpsDAO --> <bean id="TblRuleUdpsDAO" class="com.yiwei.hibernate.bean.TblRuleUdpsDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc" /> </property> </bean> <bean id="ruleUdpsServiceTarget" class="com.yiwei.business.service.RuleUdpsServiceImp"> <property name="ruleUdpsDAO"> <ref bean="TblRuleUdpsDAO" /> </property> </bean> <bean id="ruleUdpsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="ruleUdpsServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- TblReportUrlsDAO --> <bean id="TblReportUrlsDAO" class="com.yiwei.hibernate.bean.TblReportUrlsDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc"></ref> </property> </bean> <bean id="reportUrlsServiceTarget" class="com.yiwei.business.service.ReportUrlsServiceImp"> <property name="reportUrlsDAO"> <ref bean="TblReportUrlsDAO" /> </property> </bean> <bean id="reportUrlsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="reportUrlsServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- TblReportKeysDAO --> <bean id="TblReportKeysDAO" class="com.yiwei.hibernate.bean.TblReportKeysDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc" /> </property> </bean> <bean id="reportKeysServiceTarget" class="com.yiwei.business.service.ReportKeysServiceImp"> <property name="reportKeysDAO"> <ref bean="TblReportKeysDAO" /> </property> </bean> <bean id="reportKeysService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="reportKeysServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- RoleDAO --> <bean id="RoleDAO" class="com.yiwei.hibernate.bean.RoleDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp"></ref> </property> </bean> <bean id="roleServiceTarget" class="com.yiwei.business.service.RoleServiceImp"> <property name="roleDAO"> <ref bean="RoleDAO" /> </property> </bean> <bean id="roleService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="roleServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- TblReportTcpsDAO --> <bean id="TblReportTcpsDAO" class="com.yiwei.hibernate.bean.TblReportTcpsDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc" /> </property> </bean> <bean id="reportTcpsServiceTarget" class="com.yiwei.business.service.ReportTcpsServiceImp"> <property name="reportTcpsDAO"> <ref bean="TblReportTcpsDAO" /> </property> </bean> <bean id="reportTcpsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="reportTcpsServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- TblReportUdpsDAO --> <bean id="TblReportUdpsDAO" class="com.yiwei.hibernate.bean.TblReportUdpsDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc" /> </property> </bean> <bean id="reportUdpsServiceTarget" class="com.yiwei.business.service.ReportUdpsServiceImp"> <property name="reportUdpsDAO"> <ref bean="TblReportUdpsDAO" /> </property> </bean> <bean id="reportUdpsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="reportUdpsServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- SysPrincipalDAO --> <bean id="SysPrincipalDAO" class="com.yiwei.hibernate.bean.SysPrincipalDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp"></ref> </property> </bean> <bean id="sysPrincipalServiceTarget" class="com.yiwei.business.service.SysPrincipalServiceImp"> <property name="sysPrincipalDAO"> <ref bean="SysPrincipalDAO" /> </property> </bean> <bean id="sysPrincipalService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="sysPrincipalServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- TblRuleKeysDAO --> <bean id="TblRuleKeysDAO" class="com.yiwei.hibernate.bean.TblRuleKeysDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc"></ref> </property> </bean> <bean id="ruleKeysServiceTarget" class="com.yiwei.business.service.RuleKeysServiceImp"> <property name="ruleKeysDAO"> <ref bean="TblRuleKeysDAO" /> </property> <property name="logDAO"> <ref bean="LogDAO" /> </property> <property name="ruleConfsDAO"> <ref bean="TblRuleConfsDAO" /> </property> </bean> <bean id="ruleKeysService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="ruleKeysServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- TblReportProbesDAO --> <bean id="TblReportProbesDAO" class="com.yiwei.hibernate.bean.TblReportProbesDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc"></ref> </property> </bean> <bean id="reportProbesServiceTarget" class="com.yiwei.business.service.ReportProbesServiceImp"> <property name="reportProbesDAO"> <ref bean="TblReportProbesDAO" /> </property> </bean> <bean id="reportProbesService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="reportProbesServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- SysRolePrincipalDAO --> <bean id="SysRolePrincipalDAO" class="com.yiwei.hibernate.bean.SysRolePrincipalDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp" /> </property> </bean> <bean id="rolePrincipalServiceTarget" class="com.yiwei.business.service.SysRolePrincipalServiceImp"> <property name="sysRolePrincipalDAO"> <ref bean="SysRolePrincipalDAO" /> </property> </bean> <bean id="rolePrincipalService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="rolePrincipalServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- SysUserRoleDAO --> <bean id="SysUserRoleDAO" class="com.yiwei.hibernate.bean.SysUserRoleDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp" /> </property> </bean> <!-- TblReportVhostsDAO --> <bean id="TblReportVhostsDAO" class="com.yiwei.hibernate.bean.TblReportVhostsDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc" /> </property> </bean> <bean id="reportVHostServiceTarget" class="com.yiwei.business.service.ReportVHostServiceImp"> <property name="reportVhostsHostDAO"> <ref bean="TblReportVhostsDAO" /> </property> </bean> <bean id="reportVHostService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="reportVHostServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- TblRuleConfsDAO --> <bean id="TblRuleConfsDAO" class="com.yiwei.hibernate.bean.TblRuleConfsDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc" /> </property> </bean> <bean id="ruleConfsServiceTarget" class="com.yiwei.business.service.RuleConfsServiceImp"> <property name="ruleConfsDAO"> <ref bean="TblRuleConfsDAO" /> </property> </bean> <bean id="ruleConfsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="ruleConfsServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="LogDAO" class="com.yiwei.hibernate.bean.LogDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp"></ref> </property> </bean> <bean id="logServiceTarget" class="com.yiwei.business.service.LogServiceImp"> <property name="logDAO"> <ref bean="LogDAO" /> </property> </bean> <bean id="logService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="logServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="TblRuleTypeDAO" class="com.yiwei.hibernate.bean.TblRuleTypeDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc" /> </property> </bean> <bean id="ruleTypeServiceTarget" class="com.yiwei.business.service.RuleTypeServiceImp"> <property name="ruleTypeDAO"> <ref bean="TblRuleTypeDAO" /> </property> </bean> <bean id="ruleTypeService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="ruleTypeServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="HqlDAO" class="com.yiwei.hibernate.bean.HqlDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIdc" /> </property> </bean> <bean id="hqlServiceTarget" class="com.yiwei.business.service.HqlServiceImp"> <property name="hqlDao"> <ref bean="HqlDAO" /> </property> </bean> <bean id="hqlService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="hqlServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="VhostDAO" class="com.yiwei.hibernate.bean.VhostDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryIsp"></ref> </property> </bean> <bean id="vhostServiceTarget" class="com.yiwei.business.service.VHostServiceImp"> <property name="vhostDAO"> <ref bean="VhostDAO"></ref> </property> </bean> <bean id="vhostService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target"> <ref bean="vhostServiceTarget" /> </property> <property name="transactionAttributes"> <props> <prop key="get*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="find*"> PROPAGATION_REQUIRED,readOnly,-Exception </prop> <prop key="insert*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- <bean id="TblIspDAO" class="com.yiwei.hibernate.bean.TblIspDAO"> <property name="sessionFactory"> <ref bean="sessionFactoryPsb" /> </property> </bean>--></beans> /** dao public class TblRuleUrlsDAO extends HibernateDaoSupport implements IRuleUrlsDAO public void save(TblRuleUrls transientInstance) { log.debug("saving TblRuleUrls instance"); try { getHibernateTemplate().save(transientInstance); log.debug("save successful"); } catch (DataAccessException re) { log.error("save failed", re); throw re; } } /** dao class LogDAO extends HibernateDaoSupport implements ILogDAO{ public void save(Log transientInstance) { log.debug("saving Log instance"); try { getHibernateTemplate().save(transientInstance); log.debug("save successful"); } catch (DataAccessException re) { log.error("save failed", re); throw re; } } /** service public class RuleUrlsServiceImp implements IRuleUrlsService { private IRuleUrlsDAO ruleUrlsDAO; private IRuleConfsDAO ruleConfsDAO; private ILogDAO logDAO; public IRuleUrlsDAO getRuleUrlsDAO() { return ruleUrlsDAO; } public void setRuleUrlsDAO(IRuleUrlsDAO ruleUrlsDAO) { this.ruleUrlsDAO = ruleUrlsDAO; } public void delete(TblRuleUrls persistentInstance) { // TODO Auto-generated method stub this.ruleUrlsDAO.delete(persistentInstance); } public TblRuleUrls findById(Integer id) { // TODO Auto-generated method stub return this.ruleUrlsDAO.findById(id); } public void insertUser(TblRuleUrls transientInstance,User u) { // TODO Auto-generated method stub try{ this.ruleUrlsDAO.save(transientInstance); Log log = new Log(); log.setCarrierId(transientInstance.getIspID()); log.setDtime(transientInstance.getDtime()); log.setProxyerId(transientInstance.getProxyId()); String ip = transientInstance.getAssignIp().split(" ")[0]; log.setIp(ip); log.setMessage("用户  部署了url规则 "+transientInstance.getHurl()); log.setUser(u); log.setDtime("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"); //ILogService logService = (ILogService)AppContext.getInstance().getAppContext().getBean("logService"); logDAO.save(log); } catch(DataAccessException e){ System.err.println("service 抛出异常"); throw e; } } action */ public ActionForward ruleUrlsAdd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { RuleUrlsForm ruleUrlsForm = (RuleUrlsForm) form;// TODO Auto-generated // method stub try{ User u = (User) request.getSession().getAttribute("u"); TblRuleUrls url = new TblRuleUrls(); PropertyUtils.copyProperties(url, ruleUrlsForm); url.setAction(ruleUrlsForm.getAct()); url.setAssignIp(request.getRemoteAddr() + " " + u.getRealName()); url.setDtime(Conversion.getDate(new Date())); String hurl = ruleUrlsForm.getHurl(); if (ruleUrlsForm.getAct().equals("redi")||ruleUrlsForm.getAct().equals("rredi")) { hurl = hurl + " " + ruleUrlsForm.getThurl(); } url.setHurl(hurl); url.setUserID(u.getId()); url.setIspID(u.getCarrierId()); url.setProxyId(u.getProxyerId()); this.getRuleUrlsService().insertUser(url,u); }catch(DataAccessException e) { System.err.println("action 执行中发生异常"); } ActionForward f = new ActionForward("ruleUrls.do?action=ruleUrlsList", true); return f; } jta 配置文件如下 c om.atomikos.icatch.service = com.atomikos.icatch.standalone.UserTransactionServiceFactory com.atomikos.icatch.enable_logging = false com.atomikos.icatch.automatic_resource_registration = true 再次谢过 查了资料后 现将每个都加上了 <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop><prop key="save*">PROPAGATION_REQUIRED,-Exception</prop> 增加异常 但是还是不行 [b]问题补充:[/b] 现在将mysql 换成了6.0 还是不行 单数据库事务也不起作用 期待高手 [b]问题补充:[/b] 请问下3楼 会不会是table的engine是MyISAM类型的啊? 是什么意思 [b]问题补充:[/b] 三楼的 你好 我的数据类型是MyISAM类型 vhost | MyISAM | 10 | Dynamic | 9 | 348 | 3132 | 281474976710655 | 2048 | 0 | NULL | 20 8-06-17 10:48:04 | 2008-06-17 11:16:38 | NULL | utf8_general_ci | NUL | | |MyISAM
相见恨晚的超实用网站
搞学习 知乎:www.zhihu.com 简答题:http://www.jiandati.com/ 网易公开课:https://open.163.com/ted/ 网易云课堂:https://study.163.com/ 中国大学MOOC:www.icourse163.org 网易云课堂:study.163.com 哔哩哔哩弹幕网:www.bilibili.com 我要自学网:www.51zxw
花了20分钟,给女朋友们写了一个web版群聊程序
参考博客 [1]https://www.byteslounge.com/tutorials/java-ee-html5-websocket-example
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载    点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量 path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。
字节跳动视频编解码面经
引言 本文主要是记录一下面试字节跳动的经历。 三四月份投了字节跳动的实习(图形图像岗位),然后hr打电话过来问了一下会不会opengl,c++,shador,当时只会一点c++,其他两个都不会,也就直接被拒了。 七月初内推了字节跳动的提前批,因为内推没有具体的岗位,hr又打电话问要不要考虑一下图形图像岗,我说实习投过这个岗位不合适,不会opengl和shador,然后hr就说秋招更看重基础。我当时
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 顺便拉下票,我在参加csdn博客之星竞选,欢迎投票支持,每个QQ或者微信每天都可以投5票,扫二维码即可,http://m234140.nofollow.ax.
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入 假设现有4个人...
Python 基础(一):入门必备知识
目录1 标识符2 关键字3 引号4 编码5 输入输出6 缩进7 多行8 注释9 数据类型10 运算符10.1 常用运算符10.2 运算符优先级 1 标识符 标识符是编程时使用的名字,用于给变量、函数、语句块等命名,Python 中标识符由字母、数字、下划线组成,不能以数字开头,区分大小写。 以下划线开头的标识符有特殊含义,单下划线开头的标识符,如:_xxx ,表示不能直接访问的类属性,需通过类提供
这30个CSS选择器,你必须熟记(上)
关注前端达人,与你共同进步CSS的魅力就是让我们前端工程师像设计师一样进行网页的设计,我们能轻而易举的改变颜色、布局、制作出漂亮的影音效果等等,我们只需要改几行代码,不需...
国产开源API网关项目进入Apache孵化器:APISIX
点击蓝色“程序猿DD”关注我回复“资源”获取独家整理的学习资料!近日,又有一个开源项目加入了这个Java开源界大名鼎鼎的Apache基金会,开始进行孵化器。项目名称:AP...
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 欢迎 改进 留言。 演示地点跳到演示地点 html代码如下`&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;music&lt;/title&gt; &lt;meta charset="utf-8"&gt
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。 1. for - else 什么?不是 if 和 else 才
数据库优化 - SQL优化
前面一篇文章从实例的角度进行数据库优化,通过配置一些参数让数据库性能达到最优。但是一些“不好”的SQL也会导致数据库查询变慢,影响业务流程。本文从SQL角度进行数据库优化,提升SQL运行效率。 判断问题SQL 判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象 CPU消耗严重 IO等待严重 页面响应时间过长
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 c/c++ 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7
通俗易懂地给女朋友讲:线程池的内部原理
餐厅的约会 餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”我楞了一下,心里想女朋友今天是怎么了,怎么突然问出这么专业的问题,但做为一个专业人士在女朋友面前也不能露怯啊,想了一下便说:“我先给你讲讲我前同事老王的故事吧!” 大龄程序员老王 老王是一个已经北漂十多年的程序员,岁数大了,加班加不动了,升迁也无望,于是拿着手里
经典算法(5)杨辉三角
杨辉三角 是经典算法,这篇博客对它的算法思想进行了讲解,并有完整的代码实现。
编写Spring MVC控制器的14个技巧
本期目录 1.使用@Controller构造型 2.实现控制器接口 3.扩展AbstractController类 4.为处理程序方法指定URL映射 5.为处理程序方法指定HTTP请求方法 6.将请求参数映射到处理程序方法 7.返回模型和视图 8.将对象放入模型 9.处理程序方法中的重定向 10.处理表格提交和表格验证 11.处理文件上传 12.在控制器中自动装配业务类 ...
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹
面试官:你连RESTful都不知道我怎么敢要你?
面试官:了解RESTful吗? 我:听说过。 面试官:那什么是RESTful? 我:就是用起来很规范,挺好的 面试官:是RESTful挺好的,还是自我感觉挺好的 我:都挺好的。 面试官:… 把门关上。 我:… 要干嘛?先关上再说。 面试官:我说出去把门关上。 我:what ?,夺门而去 文章目录01 前言02 RESTful的来源03 RESTful6大原则1. C-S架构2. 无状态3.统一的接
求小姐姐抠图竟遭白眼?痛定思痛,我决定用 Python 自力更生!
点击蓝色“Python空间”关注我丫加个“星标”,每天一起快乐的学习大家好,我是 Rocky0429,一个刚恰完午饭,正在用刷网页浪费生命的蒟蒻...一堆堆无聊八卦信息的网页内容慢慢使我的双眼模糊,一个哈欠打出了三斤老泪,就在此时我看到了一张图片:是谁!是谁把我女朋友的照片放出来的!awsl!太好看了叭...等等,那个背景上的一堆鬼画符是什么鬼?!真是看不下去!叔叔婶婶能忍,隔壁老王的三姨妈的四表...
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看
SQL-小白最佳入门sql查询一
不要偷偷的查询我的个人资料,即使你再喜欢我,也不要这样,真的不好;
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
致 Python 初学者
欢迎来到“Python进阶”专栏!来到这里的每一位同学,应该大致上学习了很多 Python 的基础知识,正在努力成长的过程中。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 python 这门编程语言,从2009年开始单一使用 python 应对所有的开发工作,直至今天。回顾自己的学习过程,也曾经遇到过无数的困难,也曾经迷茫过、困惑过。开办这个专栏,正是为了帮助像我当年一样困惑的 Python 初学者走出困境、快速成长。希望我的经验能真正帮到你
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,...
程序员:我终于知道post和get的区别
是一个老生常谈的话题,然而随着不断的学习,对于以前的认识有很多误区,所以还是需要不断地总结的,学而时习之,不亦说乎
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU...
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1...
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员...
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC...
【技巧总结】位运算装逼指南
位算法的效率有多快我就不说,不信你可以去用 10 亿个数据模拟一下,今天给大家讲一讲位运算的一些经典例子。不过,最重要的不是看懂了这些例子就好,而是要在以后多去运用位运算这些技巧,当然,采用位运算,也是可以装逼的,不信,你往下看。我会从最简单的讲起,一道比一道难度递增,不过居然是讲技巧,那么也不会太难,相信你分分钟看懂。 判断奇偶数 判断一个数是基于还是偶数,相信很多人都做过,一般的做法的代码如下...
【管理系统课程设计】美少女手把手教你后台管理
【文章后台管理系统】URL设计与建模分析+项目源码+运行界面 栏目管理、文章列表、用户管理、角色管理、权限管理模块(文章最后附有源码) 1. 这是一个什么系统? 1.1 学习后台管理系统的原因 随着时代的变迁,现如今各大云服务平台横空出世,市面上有许多如学生信息系统、图书阅读系统、停车场管理系统等的管理系统,而本人家里就有人在用烟草销售系统,直接在网上完成挑选、购买与提交收货点,方便又快捷。 试想,若没有烟草销售系统,本人家人想要购买烟草,还要独自前往药...
8年经验面试官详解 Java 面试秘诀
作者 |胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。 Java程序员准备和投递简历的实...
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车?某胡同口的煎饼摊一年能卖出多少个煎饼?深圳有多少个产品经理?一辆公交车里能装下多少个乒乓球?一个正常成年人有多少根头发?这类估算问题,被称为费米问题,是以科学家费米命名的。为什么面试会问这种问题呢?这类问题能把两类人清楚地区分出来。一类是具有文科思维的人,擅长赞叹和模糊想象,它主要依靠的是人的第一反应和直觉,比如小孩...
碎片化的时代,如何学习
今天周末,和大家聊聊学习这件事情。 在如今这个社会,我们的时间被各类 APP 撕的粉碎。 刷知乎、刷微博、刷朋友圈; 看论坛、看博客、看公号; 等等形形色色的信息和知识获取方式一个都不错过。 貌似学了很多,但是却感觉没什么用。 要解决上面这些问题,首先要分清楚一点,什么是信息,什么是知识。 那什么是信息呢? 你一切听到的、看到的,都是信息,比如微博上的明星出轨、微信中的表情大战、抖音上的...
so easy! 10行代码写个"狗屁不通"文章生成器
前几天,GitHub 有个开源项目特别火,只要输入标题就可以生成一篇长长的文章。 背后实现代码一定很复杂吧,里面一定有很多高深莫测的机器学习等复杂算法 不过,当我看了源代码之后 这程序不到50行 尽管我有多年的Python经验,但我竟然一时也没有看懂 当然啦,原作者也说了,这个代码也是在无聊中诞生的,平时撸码是不写中文变量名的, 中文...
相关热词 如何提升c#开发能力 矩阵乘法c# c#调用谷歌浏览器 c# 去空格去转义符 c#用户登录窗体代码 c# 流 c# linux 可视化 c# mvc 返回图片 c# 像素空间 c# 日期 最后一天
立即提问