关于spring+hibernate配置jta事务提交后没有持久化到数据库(求大神帮忙看看) 30C

我的环境 spring 5.0+hibernate5.0+atomilkos 我想用二个数据库资源进行jta事物管理
一个mysql 一个oracle
这是我的配置文件:图片说明

https://img-ask.csdn.net/upload/201612/25/1482674803_698369.png

这是我的dao代码
https://img-ask.csdn.net/upload/201612/25/1482675145_855437.png

这是我的service代码
        https://img-ask.csdn.net/upload/201612/25/1482675038_683404.png

    这是单元测试
        https://img-ask.csdn.net/upload/201612/25/1482675110_107287.png

        控制台输出
        https://img-ask.csdn.net/upload/201612/25/1482675173_466045.png

        测试能通过中间没有异常抛出,是有事务参与其中。但是数据并未有持久化到数据库。看了spring 的官方文档,关于这快没有详细说明,与hibernate整合jta的详细细节。这里有个问题,配置jta事务是应该通过SessionFactory.getCurrentSession()获取Session,还是通过openSession()获取会话。但是2种方式都试过,没有提交。我单独用jdbc实现的方式,就能正常使用jta的提交与回滚功能。是不是我还有那个地方缺少配置。请大神指点一下!!

1个回答

perfectIdeal
触动心灵的旋律 谢谢,如果你看完我的配置和代码的话,这个并不能解决我的问题。。
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
关于spring+hibernate配置jta事务提交后没有持久化到数据库(求大神帮忙看看)
我的环境 spring 5.0+hibernate5.0+atomilkos 我想用二个数据库资源进行jta事物管理 一个mysql 一个oracle 这是我的配置文件:![图片说明](https://img-ask.csdn.net/upload/201612/25/1482674793_65910.png) https://img-ask.csdn.net/upload/201612/25/1482674803_698369.png 这是我的dao代码 https://img-ask.csdn.net/upload/201612/25/1482675145_855437.png 这是我的service代码 https://img-ask.csdn.net/upload/201612/25/1482675038_683404.png 这是单元测试 https://img-ask.csdn.net/upload/201612/25/1482675110_107287.png 控制台输出 https://img-ask.csdn.net/upload/201612/25/1482675173_466045.png 测试能通过中间没有异常抛出,是有事务参与其中。但是数据并未有持久化到数据库。看了spring 的官方文档,关于这快没有详细说明,与hibernate整合jta的详细细节。这里有个问题,配置jta事务是应该通过SessionFactory.getCurrentSession()获取Session,还是通过openSession()获取会话。但是2种方式都试过,没有提交。我单独用jdbc实现的方式,就能正常使用jta的提交与回滚功能。是不是我还有那个地方缺少配置。请大神指点一下!!
spring + hibernate +jta 事务不能回滚问题
[code="java"][/code] spring 配置文件 <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&amp;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&amp;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> <!-- 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,-Exception </prop><prop key="save*">PROPAGATION_REQUIRED,,-Exception </prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="update">PROPAGATION_REQUIRED</prop> <prop key="attachDirty">PROPAGATION_REQUIRED</prop> </props> </property> </bean> 相关代码 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; } } 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; } } 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 执行中发生异常"); } 小第 是按照 http://momoko8443.iteye.com/blog/190994 一个可以运行的例子 我的和这个列子差不多 这个可以回滚 但是我的不能 什么原因 已经三天了 我把仅有的分数都散了 再做不出来要下岗了 各位大哥帮帮忙啊 [b]问题补充:[/b] 大家帮帮忙 我 用的是mysql 5.02
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); } ```
SSH 中 用了atomikos集成JTA 事务后,hibernate执行任何操作失败后都不抛异常
在项目中, 用了atomikos集成JTA 事务后,hibernate执行任何操作失败后都不抛异常 比如,我用getHibernateTemplate().load方法加载一个不存在的数据都不抛出异常,或者我删除一个不存在的记录也不抛异常,谁知道这是什么原因啊??????????
多数据源配置与JTA事务问题
项目中使用两个dataSourc,两个sessionFactory.由于业务变化,需要在项目中切换数据源,单独配置多数据源以及单独配置JTA都能成功,将多数据与JTA整合之后,项目启动总是抛出异常。 异常如下: ``` org.springframework.transaction.IllegalTransactionStateException: Pre-bound JDBC Connection found! HibernateTransactionManager does not support running within DataSourceTransactionManager if told to manage the DataSource itself. It is recommended to use a single HibernateTransactionManager for all transactions on a single DataSource, no matter whether Hibernate or JDBC access. ``` 网上说是jdbc的事务与hibernate的事务起冲突了,但没有找到解决办法,求大神指点。 ``` 1 <!-- atomikos事务管理器 --> 2 <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" 3 init-method="init" destroy-method="close"> 4 <description>UserTransactionManager</description> 5 <property name="forceShutdown"><value>true</value></property> 6 </bean> 7 8 <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> 9 <property name="transactionTimeout" value="300" /> 10 </bean> 11 12 <!-- spring 事务管理器 --> 13 <bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> 14 <property name="transactionManager" ref="atomikosTransactionManager"/> 15 <property name="userTransaction" ref="atomikosUserTransaction"/> 16 </bean> ``` AOP配置: ``` 1 <aop:aspectj-autoproxy /> 2 <aop:config proxy-target-class="true"> 3 <aop:advisor pointcut="execution(* com.animoor.m2.application..*.*(..))" advice-ref="txAdvice" /> 4 </aop:config> 5 6 <tx:advice id="txAdvice" transaction-manager="springTransactionManager"> 7 <tx:attributes> 8 <tx:method name="get*" read-only="true" /> 9 <tx:method name="find*" read-only="true" /> 10 <tx:method name="insert*" propagation="REQUIRED"/> 11 <tx:method name="update*" propagation="REQUIRED" /> 12 <tx:method name="add*" propagation="REQUIRED" /> 13 <tx:method name="delete*" propagation="REQUIRED" /> 14 <tx:method name="update*" propagation="REQUIRED" /> 15 16 <tx:method name="save*" propagation="REQUIRED" /> 17 <tx:method name="do*" propagation="REQUIRED" /> 18 .... 19 </tx:attributes> 20 </tx:advice> ``` 加入多数据源配置: ``` 1 <bean id="multipleDataSource" class="com.animoor.m2.sys.MultipleDataSource"> 2 <property name="defaultTargetDataSource" ref="dataSourceMes129"/> 3 <property name="targetDataSources"> 4 <map key-type="java.lang.String"> 5 <!--注意这里的value是和上面的DataSource的id对应,key要和下面的CustomerContextHolder中的常量对应 --> 6 <entry key="dataSourceMes129" value-ref="dataSourceMes129" /> 7 <entry key="dataSourceFgms129" value-ref="dataSourceFgms129"/> 8 <entry key="dataSourceMes168" value-ref="dataSourceMes168" /> 9 <entry key="dataSourceFgms168" value-ref="dataSourceFgms168"/> 10 </map> 11 </property> 12 </bean> ``` 项目加载时调用的方法含get*,find*,将这些get去掉则不会抛出异常,但是去掉之后事务应该没有作用了吧。 请各位大神指点 谢谢 小弟没有金币悬赏,谢谢各位了。
为什么在JMS中使用JTA事务控制全局事务失效
package cn.producer; import java.util.Properties; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; import javax.jms.ExceptionListener; import javax.jms.JMSException; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; import javax.transaction.NotSupportedException; import javax.transaction.RollbackException; import javax.transaction.SystemException; import javax.transaction.UserTransaction; public class ExceptionMessageSender { /** * 本地获取Context * 需要添加wlclient.jar , webservices.jar , wljmsclient.jar * @return */ private Context getInitialContext(){ Context context = null; final String INIT_FACTORY = "weblogic.jndi.WLInitialContextFactory"; final String SERVER_URL = "t3://localhost:7001"; Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, INIT_FACTORY); props.put(Context.PROVIDER_URL, SERVER_URL); try { context = new InitialContext(props); } catch (NamingException e) { e.printStackTrace(); } return context; } public void sendMessage() throws NamingException, JMSException, NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException{ //定义默认的weblogic的JNDI final String CONNECTION_FACTORY_JNDI = "weblogic.jms.ConnectionFactory"; //获取Context Context context = getInitialContext(); //获取连接工厂 ConnectionFactory cf = (ConnectionFactory) context.lookup(CONNECTION_FACTORY_JNDI); //获取连接 Connection conn = cf.createConnection(); //监听JMS服务器异常情况(只有当JMS服务器运行时发生的异常才会触发异常监听器) conn.setExceptionListener(new ExceptionListener(){ @Override public void onException(JMSException e) { System.out.println("JMS服务器发生异常,异常信息如下:"); e.printStackTrace(); } }); //获取JTA事务 UserTransaction tx = (UserTransaction) context.lookup("javax.transaction.UserTransaction"); tx.begin(); //获取会话,如果设置为事务性会话,那么JTA不起作用 Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); //获取消息目的 Destination dest = (Destination) context.lookup("MessageQueue"); //通过会话获取消息生产者 MessageProducer sender = session.createProducer(dest); //通过会话创建一个空格JMS消息 TextMessage msg = session.createTextMessage(); msg.setText("你好,我是路人甲!"); //通过消息生产者发送消息 sender.send(msg); try{ int num = 4/0;//-----------这里会抛出异常,引发JTA全局事务回滚 msg.setText(num+":number"); sender.send(msg); tx.commit(); }catch(Exception e){ tx.rollback(); }finally{ //关闭资源 session.close(); conn.close(); } } } package cn.consumer; import java.util.Properties; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; import javax.jms.ExceptionListener; import javax.jms.JMSException; import javax.jms.MessageConsumer; import javax.jms.Session; import javax.jms.TextMessage; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; import javax.transaction.NotSupportedException; import javax.transaction.RollbackException; import javax.transaction.SystemException; import javax.transaction.UserTransaction; public class ExceptionConsumer { /** * 本地获取Context * 需要添加wlclient.jar , webservices.jar , wljmsclient.jar * @return */ private Context getInitialContext(){ Context context = null; final String INIT_FACTORY = "weblogic.jndi.WLInitialContextFactory"; final String SERVER_URL = "t3://localhost:7001"; Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY, INIT_FACTORY); props.put(Context.PROVIDER_URL, SERVER_URL); try { context = new InitialContext(props); } catch (NamingException e) { e.printStackTrace(); } return context; } public void receiveMessage() throws NamingException, JMSException, NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException{ //定义默认的weblogic连接工程的JNDI final String CONNECTION_FACTORY_JNDI = "weblogic.jms.ConnectionFactory"; //获取Context Context context = getInitialContext(); //通过JNDI获取连接工厂 ConnectionFactory cf = (ConnectionFactory) context.lookup(CONNECTION_FACTORY_JNDI); //通过连接工厂获取连接 Connection conn = cf.createConnection(); //开始JMS传输 conn.start(); //设置异常监听器,监听JMS服务器上的异常 conn.setExceptionListener(new ExceptionListener(){ public void onException(JMSException e){ System.out.println("JMS服务器发生异常,异常信息如下:"); e.printStackTrace(); } }); //打开全局事务 UserTransaction tx = (UserTransaction) context.lookup("javax.transaction.UserTransaction"); tx.begin(); //通过连接获取会话,使用全局事务了,就不应该设置为事务性会话,否则全局事务会失效,使用的事务还是事务性会话的事务 Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); //获取消息目的(消息队列) Destination dest = (Destination) context.lookup("MessageQueue"); //创建消息消费者 MessageConsumer receiver = session.createConsumer(dest); //消息消费者同步接收消息 TextMessage msg = (TextMessage) receiver.receiveNoWait(); System.out.println(msg); if(msg != null){ System.out.println("同步接收到信息:"+msg.getText()); } //确认事务 tx.commit(); //关闭资源 session.close(); conn.close(); } } package cn.test; import javax.jms.JMSException; import javax.naming.NamingException; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; import javax.transaction.NotSupportedException; import javax.transaction.RollbackException; import javax.transaction.SystemException; import cn.producer.ExceptionMessageSender; public class TestExceptionProducer { public static void main(String[] args) { ExceptionMessageSender ems = new ExceptionMessageSender(); try { ems.sendMessage(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (NamingException e) { e.printStackTrace(); } catch (JMSException e) { e.printStackTrace(); } catch (NotSupportedException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } catch (RollbackException e) { e.printStackTrace(); } catch (HeuristicMixedException e) { e.printStackTrace(); } catch (HeuristicRollbackException e) { e.printStackTrace(); } } } ``` ``` 代码贴在上面,我的意思就是不用JMS自带的事务,而用JTA来控制全局事务。但是没找到失效的原因。
mybatis+spring的事务@Transactional的NOT_SUPPORTED无效
method1方法有事务,method2不需要事务(设置为NOT_SUPPORTED),但是在执行的时候method2还是用到了事务。 求大神指导,, ``` @Transactional public void method1(HtYbnsrDab htYbnsrDab) { // .....业务逻辑 method2(); } @Transactional(propagation = Propagation.NOT_SUPPORTED) public void method2(HtYbnsrDab htYbnsrDab) { // .....业务逻辑 } ``` 使用的是jta事务,web容器是weblogic,spring配置如下: ``` <jee:jndi-lookup id="htssDS" jndi-name="htssDS"/> <tx:jta-transaction-manager/> <tx:annotation-driven proxy-target-class="true"/> ```
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(); } } ``` 哪位大神遇到过这种情况的请分享一下,不胜感激。
全局事务(JTA事务)的原子性
现有两个事务资源datasource1,datasource2假如我不采用XA规范而是简单的[code="java"] try{ do transaction 1; do transaction 2; commit transaction 1;//① commit transaction 2;//② }catch(exception){ rollback transaction 1; rollback transaction 2; } [/code] 这样做是管理两个事务 和通过X/OPEN XA(JTA)的两阶段提交有何区别。 是不是JTA可以在①②处保证原子性,而管理两个事务则不能?
Spring hibernate 整合问题
2009-3-17 14:24:38 org.apache.catalina.core.AprLifecycleListener init 信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Program Files\Java\jre1.6.0_04\bin;D:\Program Files\MyEclipse 6.0\eclipse\plugins\com.genuitec.eclipse.easie.tomcat.myeclipse_6.0.1.zmyeclipse601200710\tomcat\bin 2009-3-17 14:24:38 org.apache.coyote.http11.Http11Protocol init 信息: Initializing Coyote HTTP/1.1 on http-8080 2009-3-17 14:24:38 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 994 ms 2009-3-17 14:24:38 org.apache.catalina.core.StandardService start 信息: Starting service Catalina 2009-3-17 14:24:38 org.apache.catalina.core.StandardEngine start 信息: Starting Servlet Engine: Apache Tomcat/6.0.13 log4j:WARN No such property [conversionPattern] in org.apache.log4j.TTCCLayout. 2009-3-17 14:24:40 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring root WebApplicationContext 2009-03-17 14:24:40 [org.springframework.web.context.ContextLoader]-[INFO] Root WebApplicationContext: initialization started 2009-03-17 14:24:41 [org.springframework.web.context.support.XmlWebApplicationContext]-[INFO] Refreshing org.springframework.web.context.support.XmlWebApplicationContext@1d0e2c9: display name [Root WebApplicationContext]; startup date [Tue Mar 17 14:24:41 CST 2009]; root of context hierarchy 2009-03-17 14:24:41 [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]-[INFO] Loading XML bean definitions from URL [file:/E:/Test/workspace/.metadata/.plugins/com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/supermarket/WEB-INF/classes/config/spring/applicationContext.xml] 2009-03-17 14:24:42 [org.springframework.web.context.support.XmlWebApplicationContext]-[INFO] Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@1d0e2c9]: org.springframework.beans.factory.support.DefaultListableBeanFactory@5e7663 2009-03-17 14:24:42 [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[INFO] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5e7663: defining beans [sessionFactorys,registerOperatorDAO,registerOperatorService,registerOperatorAction]; root of factory hierarchy 2009-03-17 14:24:42 [org.springframework.beans.factory.support.DefaultListableBeanFactory]-[INFO] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5e7663: defining beans [sessionFactorys,registerOperatorDAO,registerOperatorService,registerOperatorAction]; root of factory hierarchy 2009-03-17 14:24:42 [org.springframework.web.context.ContextLoader]-[ERROR] Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactorys' defined in URL [file:/E:/Test/workspace/.metadata/.plugins/com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/supermarket/WEB-INF/classes/config/spring/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440) 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:221) 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:423) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381) 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:3827) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) 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:566) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877) ... 40 more Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.class$(LocalSessionFactoryBean.java:174) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.<init>(LocalSessionFactoryBean.java:174) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100) ... 42 more Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) at java.lang.ClassLoader.loadClassInternal(Unknown Source) ... 51 more 2009-3-17 14:24:42 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 'sessionFactorys' defined in URL [file:/E:/Test/workspace/.metadata/.plugins/com.genuitec.eclipse.easie.tomcat.myeclipse/tomcat/webapps/supermarket/WEB-INF/classes/config/spring/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440) 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:221) 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:423) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381) 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:3827) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4334) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920) at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) 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:566) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/dom4j/DocumentException at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877) ... 40 more Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.class$(LocalSessionFactoryBean.java:174) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.<init>(LocalSessionFactoryBean.java:174) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100) ... 42 more Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) at java.lang.ClassLoader.loadClassInternal(Unknown Source) ... 51 more 2009-3-17 14:24:42 org.apache.catalina.core.StandardContext start 严重: Error listenerStart 2009-3-17 14:24:42 org.apache.catalina.core.StandardContext start 严重: Context [/supermarket] startup failed due to previous errors 2009-3-17 14:24:42 org.apache.catalina.core.ApplicationContext log 信息: Closing Spring root WebApplicationContext 2009-3-17 14:24:43 org.apache.coyote.http11.Http11Protocol start 信息: Starting Coyote HTTP/1.1 on http-8080 2009-3-17 14:24:43 org.apache.jk.common.ChannelSocket init 信息: JK: ajp13 listening on /0.0.0.0:8009 2009-3-17 14:24:43 org.apache.jk.server.JkMain start 信息: Jk running ID=0 time=0/47 config=null 2009-3-17 14:24:43 org.apache.catalina.startup.Catalina start 信息: Server startup in 4940 ms 配置文件如下 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="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" default-autowire="byName"> <bean name="sessionFactorys" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean> <bean name="registerOperatorDAO" class="org.xsd.supermarket.system.operator.operator.impl.OperatorDAOImpl"> <property name="sessionFactorys" ref="sessionFactorys"></property> </bean> <bean name="registerOperatorService" class="org.xsd.supermarket.system.operator.operator.impl.OperatorServicesImpl"> <property name="registerOperatorDAO" ref="registerOperatorDAO"></property> </bean> <bean name="registerOperatorAction" class="org.xsd.supermarket.system.operator.operator.OperatorAction"> <property name="registerOperatorService" ref="registerOperatorService"></property> </bean> </beans> 用到的JAR包如下: <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/hibernate/hibernate3.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/spring/spring.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts/commons-logging-1.0.4.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts/freemarker-2.3.13.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts/ognl-2.6.11.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts/struts2-core-2.1.6.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts/struts2-spring-plugin-2.1.6.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/struts/xwork-2.1.2.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tools/log4j-1.2.14.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tools/mysql-connector-java-5.0.5-bin.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tools/commons-beanutils.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tools/dom4j-1.6.1.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tools/jaxen-1.1-beta-7.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tools/cglib-nodep-2.1_3.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tools/asm-2.2.3.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tools/asm-commons-2.2.3.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tools/asm-util-2.2.3.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tools/jta.jar"/> <classpathentry kind="lib" path="WebRoot/WEB-INF/lib/tools/aspectjweaver.jar"/>
SSH 中 atomikos集成JTA 事务无法回滚
applicationContext.xml配置文件如下 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" 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.0.xsd"> <bean id="dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <description>oracle xa datasource</description> <property name="uniqueResourceName"> <value>oracle1</value> </property> <property name="xaDataSourceClassName"> <value>oracle.jdbc.xa.client.OracleXADataSource</value> </property> <property name="xaProperties"> <props> <prop key="user">test</prop> <prop key="password">test</prop> <prop key="URL">jdbc:oracle:thin:@192.168.0.28:1521:test</prop> </props> </property> </bean> <bean id="dataSourceOracle" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <property name="uniqueResourceName"> <value>oracle2</value> </property> <property name="xaDataSourceClassName"> <value>oracle.jdbc.xa.client.OracleXADataSource</value> </property> <property name="xaProperties"> <props> <prop key="user">test1</prop> <prop key="password">test1</prop> <prop key="URL">jdbc:oracle:thin:@192.168.0.28:1521:test</prop> </props> </property> </bean> <bean id="sessionFactory1" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9Dialect </prop> <prop key="hibernate .show_sql">true</prop> <prop key="hibernate.max_fetch_depth">1</prop> <prop key="hibernate.jdbc.fetch_size">20</prop> <prop key="hibernate.query.factory_class"> org.hibernate.hql.ast.ASTQueryTranslatorFactory </prop> </props> </property> <property name="jtaTransactionManager" ref="atomikosTransactionManager" /> <property name="mappingDirectoryLocations"> <list> <value> classpath*:com/yappam/model/ </value> </list> </property> </bean> <bean id="sessionFactory2" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSourceOracle" /> </property> <property name="hibernateProperties"> <props>[b][/b] <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9Dialect </prop> <prop key="hibernate .show_sql">true</prop> <prop key="hibernate.max_fetch_depth">1</prop> <prop key="hibernate.jdbc.fetch_size">20</prop> <prop key="hibernate.query.factory_class"> org.hibernate.hql.ast.ASTQueryTranslatorFactory </prop> </props> </property> <property name="jtaTransactionManager" ref="atomikosTransactionManager" /> <property name="mappingLocations"> <list> <value> classpath*:com/yappam/model/oracle/*.hbm.xml </value> </list> </property> </bean> <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="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="userTransaction" ref="atomikosUserTransaction" /> <property name="transactionManager" ref="atomikosTransactionManager"> </property> </bean> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> <property name="transactionTimeout"> <value>240</value> </property> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception" /> <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception" /> <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception" /> <tx:method name="*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <aop:config proxy-target-class="true"> <aop:pointcut id="iPointCuts" expression="execution(* com.yappam.service.impl..*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="iPointCuts" /> </aop:config> </beans> 如果将事务的隔离界别设置成 read-only="true",则两个数据库都才、不能插入数据, 但是我现在 User user=new User(); user.setId("0000000000128359568004600001372");//不存在数据 userDao.delete(user); Test t=new Test(); t.setId(IDGenerator.getId()); t.setUsername("222"); testDao.save(t); 我先删除一条不存在信息抛出异常,但是事务却不回滚,任然可以有一个数据库插入成功? 请大家帮忙解决下!谢谢
JTA使用Propagation.NESTED事务传播方式报错
# JTA使用Propagation.NESTED事务传播方式报错 spring boot配置JTA后,使用Propagation.NESTED事务传播方式,出现异常,切换其他传播方式代码正常。 <br/> 事务配置: A service: @Transactional @Override public void saveOrUpdate(Msg msg) { msgJDBCDAO.save(msg); MsgReceiver msgReceiver = new MsgReceiver(); msgReceiver.setId(msg.getMsgId()); msgReceiver.setMsgId(msg.getMsgId()); msgReceiver.setUserId(1000L); msgReceiver.setReadFlag(0); msgReceiver.setDeleteFlag(0); msgReceiverJDBCService.save(msgReceiver); } B service: @Transactional(propagation = Propagation.NESTED) @Override public void save(MsgReceiver msgReceiver) { msgReceiverJDBCDAO.save(msgReceiver); } <br/> <br/><br/><br/> ## 报错信息如下: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [insert into t_msg_receiver values (?, ?, ?, ?, ?)]; SQL state [null]; error code [0]; Failed to suspend branch: XAResourceTransaction: 3139322E3136382E3232372E322E746D313537343036303233343835373030303031:3139322E3136382E3232372E322E746D31; nested exception is com.atomikos.jdbc.AtomikosSQLException: Failed to suspend branch: XAResourceTransaction: 3139322E3136382E3232372E322E746D313537343036303233343835373030303031:3139322E3136382E3232372E322E746D31 at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1442) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:632) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:861) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:916) at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:926) at com.spring.boot.example.dao.jdbc.MsgReceiverJDBCDAO.save(MsgReceiverJDBCDAO.java:16) at com.spring.boot.example.dao.jdbc.MsgReceiverJDBCDAO$$FastClassBySpringCGLIB$$bdb85c72.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.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) at com.spring.boot.example.dao.jdbc.MsgReceiverJDBCDAO$$EnhancerBySpringCGLIB$$6e56ffb6.save(<generated>) at com.spring.boot.example.service.jdbc.impl.MsgReceiverJDBCServiceImpl.save(MsgReceiverJDBCServiceImpl.java:21) at com.spring.boot.example.service.jdbc.impl.MsgReceiverJDBCServiceImpl$$FastClassBySpringCGLIB$$a40f40ea.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:295) 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.spring.boot.example.service.jdbc.impl.MsgReceiverJDBCServiceImpl$$EnhancerBySpringCGLIB$$65349f92.save(<generated>) at com.spring.boot.example.service.jdbc.impl.MsgJDBCServiceImpl.saveOrUpdate(MsgJDBCServiceImpl.java:46) at com.spring.boot.example.service.jdbc.impl.MsgJDBCServiceImpl$$FastClassBySpringCGLIB$$a07b1dd9.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:295) 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.spring.boot.example.service.jdbc.impl.MsgJDBCServiceImpl$$EnhancerBySpringCGLIB$$ecf643bf.saveOrUpdate(<generated>) at com.spring.boot.example.service.MsgJDBCServiceTest.test(MsgJDBCServiceTest.java:28) 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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) 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.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: com.atomikos.jdbc.AtomikosSQLException: Failed to suspend branch: XAResourceTransaction: 3139322E3136382E3232372E322E746D313537343036303233343835373030303031:3139322E3136382E3232372E322E746D31 at com.atomikos.jdbc.AtomikosSQLException.throwAtomikosSQLException(AtomikosSQLException.java:29) at com.atomikos.jdbc.AtomikosConnectionProxy.enlist(AtomikosConnectionProxy.java:217) at com.atomikos.jdbc.AtomikosConnectionProxy.invoke(AtomikosConnectionProxy.java:122) at com.sun.proxy.$Proxy98.prepareStatement(Unknown Source) at org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement(JdbcTemplate.java:1555) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:614) ... 63 more Caused by: com.atomikos.datasource.xa.session.InvalidSessionHandleStateException: Failed to suspend branch: XAResourceTransaction: 3139322E3136382E3232372E322E746D313537343036303233343835373030303031:3139322E3136382E3232372E322E746D31 at com.atomikos.datasource.xa.session.BranchEnlistedStateHandler.transactionSuspended(BranchEnlistedStateHandler.java:98) at com.atomikos.datasource.xa.session.TransactionContext.transactionSuspended(TransactionContext.java:94) at com.atomikos.datasource.xa.session.SessionHandleState.notifyBeforeUse(SessionHandleState.java:165) at com.atomikos.jdbc.AtomikosConnectionProxy.enlist(AtomikosConnectionProxy.java:207) ... 67 more Caused by: com.mysql.cj.jdbc.MysqlXAException: XAER_INVAL: Invalid arguments (or unsupported command) at com.mysql.cj.jdbc.MysqlXAConnection.mapXAExceptionFromSQLException(MysqlXAConnection.java:344) at com.mysql.cj.jdbc.MysqlXAConnection.dispatchCommand(MysqlXAConnection.java:329) at com.mysql.cj.jdbc.MysqlXAConnection.end(MysqlXAConnection.java:267) at com.atomikos.datasource.xa.XAResourceTransaction.xaSuspend(XAResourceTransaction.java:700) at com.atomikos.datasource.xa.session.BranchEnlistedStateHandler.transactionSuspended(BranchEnlistedStateHandler.java:94) ... 70 more Caused by: java.sql.SQLException: XAER_INVAL: Invalid arguments (or unsupported command) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:764) at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:648) at
spring+hibernate游标不释放问题
系统使用spring+hibernate连接池与spring事务设置如下: [code="java"] <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>oracle.jdbc.driver.OracleDriver</value> </property> <property name="jdbcUrl"> <value>jdbc:oracle:thin:@192.168.1.106:1521:orcl</value> </property> <property name="user"> <value>wjcx</value> </property> <property name="password"> <value>wjcx</value> </property> <!--连接池中保留的最小连接数。--> <property name="minPoolSize"> <value>5</value> </property> <!--连接池中保留的最大连接数。Default: 15 --> <property name="maxPoolSize"> <value>30</value> </property> <!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 --> <property name="initialPoolSize"> <value>10</value> </property> <!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --> <property name="maxIdleTime"> <value>60</value> </property> <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --> <property name="acquireIncrement"> <value>5</value> </property> <!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements 属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。 如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0--> <property name="maxStatements"> <value>0</value> </property> <!--每60秒检查所有连接池中的空闲连接。Default: 0 --> <property name="idleConnectionTestPeriod"> <value>60</value> </property> <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 --> <property name="acquireRetryAttempts"> <value>30</value> </property> <!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效 保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试 获取连接失败后该数据源将申明已断开并永久关闭。Default: false--> <property name="breakAfterAcquireFailure"> <value>true</value> </property> <!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的 时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable 等方法来提升连接测试的性能。Default: false --> <property name="testConnectionOnCheckout"> <value>false</value> </property> </bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource"> <ref bean="dataSource" /> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.cache.provider_class">com.jweb.common.cache.OSCacheProvider</prop> <prop key="hibernate.cache.use_query_cache">false</prop> </props> </property> </bean> <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="baseTxProxy" abstract="true" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> <property name="transactionAttributes"> <props> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="list*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="add*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="edit*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="create*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="remove*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> [/code] dao中的代码如下 [code="java"] public List getListByArticle(ArticleModel article, String orderby, int firstResult, int maxResults,String tid) { String hql = "from UserModel"; Session session = this.getSession(); Query query = session.createQuery(hql); query.setFirstResult(firstResult); query.setMaxResults(maxResults); return query.list(); } [/code] 里面有很多如上面的方法:但系统运行一段时间后总是游标超出最大值!因为用了spring事务,service类中没有关闭连接.但不知道为什么游标老是超出,希望有人解答! [b]问题补充:[/b] 程序有些地方使用了HibernateTemplate这个,但因为存在一些复杂SQL的组装只想知道上面这种写法会不会关掉游标的. [b]问题补充:[/b] 不是使用spring的事务管理就不用关连接吗 [b]问题补充:[/b] 发现添加了session.close();系统后就会报得不到session了!象上面这种写法有什么补求的办法吗?因为代码已经写了很多了!
hibernate4为什么在执行save ()后直接查询直接查询不到数据?
![图片说明](https://img-ask.csdn.net/upload/201511/18/1447830636_399666.png)hibernate4为什么在执行save ()后直接查询直接查询不到数据 同样的配置在hibernate3这样是能查询到数据的,换到hibernate4就是查不到, 就像save()操作没有把对象缓存一样,这样是为什么呀?下面是配置 <property name="dialect"> org.hibernate.dialect.MySQL5InnoDBDialect </property> <property name="current_session_context_class">jta</property> <property name="hibernate.transaction.factory_class"> org.hibernate.transaction.JTATransactionFactory </property> <property name="hibernate.transaction.manager_lookup_class"> com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup </property> <property name="connection.release_mode">auto</property> <property name="hibernate.transaction.flush_before_completion"> true </property> <property name="hibernate.transaction.auto_close_session"> true </property> 事务用的JTA java代码时在同一个事务里添加和查询的: User user = new User() user.setOid("123"); ... Dao.save(user); list lst = Dao.query("User","where oid='123'"); 结果lst为空 理论上save后对象应该缓存在Session里的吧,查询的话也应该查询到缓存里对象吧,可是为什么查询不到呢? 经过验证,对象确实在session里,但是在同一个事务内就是查询不到,为什么呢?
springboot+jpa+jta-atomikos多数据源事务异常
springboot + jpa配置jta事务,出现第一个数据源可以正常使用,但第二个只能查询,不能CRUD操作,求大神指点 第一个数据源如下: @Configuration @EnableTransactionManagement @EnableJpaRepositories(basePackages = "com.saxon.primary.dao", entityManagerFactoryRef = "primaryEntityManagerFactory", transactionManagerRef = "jtaTransactionManager") public class PrimaryDataSourceConfig { @Bean @Primary @ConfigurationProperties("spring.primary.datasource") public DataSourceProperties primaryProperties(){ return new DataSourceProperties(); } @Bean @Primary @ConfigurationProperties("spring.primary.datasource") public DataSource primaryDataSource(){ return primaryProperties().initializeDataSourceBuilder().build(); } @Bean @Primary public LocalContainerEntityManagerFactoryBean primaryEntityManagerFactory(EntityManagerFactoryBuilder builder){ return builder .dataSource(primaryDataSource()) .persistenceUnit("primary") .packages("com.saxon.primary.entity") .build(); } } 第二个数据源: @Configuration @EnableTransactionManagement @EnableJpaRepositories(basePackages = "com.saxon.others.dao", entityManagerFactoryRef = "othersEntityManagerFactory", transactionManagerRef = "jtaTransactionManager") public class OthersDataSourceConfig { @Bean @ConfigurationProperties("spring.others.datasource") public DataSourceProperties othersProperties(){ return new DataSourceProperties(); } @Bean @ConfigurationProperties("spring.others.datasource") public DataSource othersDataSource(){ return othersProperties().initializeDataSourceBuilder().build(); } @Bean public LocalContainerEntityManagerFactoryBean othersEntityManagerFactory(EntityManagerFactoryBuilder builder){ return builder .dataSource(othersDataSource()) .persistenceUnit("others") .packages("com.saxon.others.entity") .build(); } } jta事务配置: @Configuration @EnableTransactionManagement public class TransactionManagerConfig { @Bean(destroyMethod = "close", initMethod = "init") public UserTransactionManager userTransactionManager() { UserTransactionManager userTransactionManager = new UserTransactionManager(); userTransactionManager.setForceShutdown(false); return userTransactionManager; } public @Bean UserTransaction userTransaction() throws Throwable { UserTransactionImp userTransactionImp = new UserTransactionImp(); userTransactionImp.setTransactionTimeout(300); return userTransactionImp; } public @Bean PlatformTransactionManager jtaTransactionManager() throws Throwable { JtaTransactionManager jtaTransactionManager = new JtaTransactionManager(); jtaTransactionManager.setTransactionManager(userTransactionManager()); jtaTransactionManager.setUserTransaction(userTransaction()); return jtaTransactionManager; } } 但执行第二个数据源的crud操作,报如下异常: 2017-07-20 18:00:43.131 ERROR 46084 --- [nio-9008-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress] with root cause javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.jpa.spi.AbstractEntityManagerImpl.checkTransactionNeeded(AbstractEntityManagerImpl.java:1136) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1297) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121] at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:347) ~[spring-orm-4.3.9.RELEASE.jar:4.3.9.RELEASE] at com.sun.proxy.$Proxy76.flush(Unknown Source) ~[na:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
hibernate解压后的geronimo-jta_1.1_spec-1.1.1.jar
我怎么在最新版本的hibernate下找不到这个包了,请问集成到哪个包里了,我的hibernate 的版本是 hibernate-release-5.2.11.Final
jta事务异常回滚时报错
在进行频繁更新数据库后出现如下错误: ![图片说明](https://img-ask.csdn.net/upload/201612/26/1482732197_497827.png) 事务配置如下: <tx:method name="update*" propagation="REQUIRES_NEW" rollback-for="Exception"/> <tx:method name="sel*" propagation="REQUIRES_NEW" rollback-for="Exception"/> 请问各位大神这是什么原因 紧急
spring4.x对JOTM的支持
今天突然兴起,想测试下Spring的JTA,百度查看到spring使用JTOM对分布式事务进行控制, 准备配置beanx.xml文件, bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" spring4.1.7怎么查也查不到这个类,2.5.6中有,这意味着这玩意儿过时了? 可否有大拿提供对应的解决方案?基于4.x
终于明白阿里百度这样的大公司,为什么面试经常拿ThreadLocal考验求职者了
点击上面↑「爱开发」关注我们每晚10点,捕获技术思考和创业资源洞察什么是ThreadLocalThreadLocal是一个本地线程副本变量工具类,各个线程都拥有一份线程私...
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
Linux(服务器编程):15---两种高效的事件处理模式(reactor模式、proactor模式)
前言 同步I/O模型通常用于实现Reactor模式 异步I/O模型则用于实现Proactor模式 最后我们会使用同步I/O方式模拟出Proactor模式 一、Reactor模式 Reactor模式特点 它要求主线程(I/O处理单元)只负责监听文件描述符上是否有事件发生,有的话就立即将时间通知工作线程(逻辑单元)。除此之外,主线程不做任何其他实质性的工作 读写数据,接受新的连接,以及处...
阿里面试官问我:如何设计秒杀系统?我的回答让他比起大拇指
你知道的越多,你不知道的越多 点赞再看,养成习惯 GitHub上已经开源 https://github.com/JavaFamily 有一线大厂面试点脑图和个人联系方式,欢迎Star和指教 前言 Redis在互联网技术存储方面使用如此广泛,几乎所有的后端技术面试官都要在Redis的使用和原理方面对小伙伴们进行360°的刁难。 作为一个在互联网公司面一次拿一次Offer的面霸,打败了...
五年程序员记流水账式的自白。
不知觉已中码龄已突破五年,一路走来从起初铁憨憨到现在的十九线程序员,一路成长,虽然不能成为高工,但是也能挡下一面,从15年很火的android开始入坑,走过java、.Net、QT,目前仍处于android和.net交替开发中。 毕业到现在一共就职过两家公司,目前是第二家,公司算是半个创业公司,所以基本上都会身兼多职。比如不光要写代码,还要写软著、软著评测、线上线下客户对接需求收集...
C语言魔塔游戏
很早就很想写这个,今天终于写完了。 游戏截图: 编译环境: VS2017 游戏需要一些图片,如果有想要的或者对游戏有什么看法的可以加我的QQ 2985486630 讨论,如果暂时没有回应,可以在博客下方留言,到时候我会看到。 下面我来介绍一下游戏的主要功能和实现方式 首先是玩家的定义,使用结构体,这个名字是可以自己改变的 struct gamerole { char n...
一文详尽系列之模型评估指标
点击上方“Datawhale”,选择“星标”公众号第一时间获取价值内容在机器学习领域通常会根据实际的业务场景拟定相应的不同的业务指标,针对不同机器学习问题如回归、分类、排...
究竟你适不适合买Mac?
我清晰的记得,刚买的macbook pro回到家,开机后第一件事情,就是上了淘宝网,花了500元钱,找了一个上门维修电脑的师傅,上门给我装了一个windows系统。。。。。。 表砍我。。。 当时买mac的初衷,只是想要个固态硬盘的笔记本,用来运行一些复杂的扑克软件。而看了当时所有的SSD笔记本后,最终决定,还是买个好(xiong)看(da)的。 已经有好几个朋友问我mba怎么样了,所以今天尽量客观...
程序员一般通过什么途径接私活?
二哥,你好,我想知道一般程序猿都如何接私活,我也想接,能告诉我一些方法吗? 上面是一个读者“烦不烦”问我的一个问题。其实不止是“烦不烦”,还有很多读者问过我类似这样的问题。 我接的私活不算多,挣到的钱也没有多少,加起来不到 20W。说实话,这个数目说出来我是有点心虚的,毕竟太少了,大家轻喷。但我想,恰好配得上“一般程序员”这个称号啊。毕竟苍蝇再小也是肉,我也算是有经验的人了。 唾弃接私活、做外...
压测学习总结(1)——高并发性能指标:QPS、TPS、RT、吞吐量详解
一、QPS,每秒查询 QPS:Queries Per Second意思是“每秒查询率”,是一台服务器每秒能够相应的查询次数,是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准。互联网中,作为域名系统服务器的机器的性能经常用每秒查询率来衡量。 二、TPS,每秒事务 TPS:是TransactionsPerSecond的缩写,也就是事务数/秒。它是软件测试结果的测量单位。一个事务是指一...
Python爬虫爬取淘宝,京东商品信息
小编是一个理科生,不善长说一些废话。简单介绍下原理然后直接上代码。 使用的工具(Python+pycharm2019.3+selenium+xpath+chromedriver)其中要使用pycharm也可以私聊我selenium是一个框架可以通过pip下载 pip installselenium -ihttps://pypi.tuna.tsinghua.edu.cn/simple/ ...
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
Java工作4年来应聘要16K最后没要,细节如下。。。
前奏: 今天2B哥和大家分享一位前几天面试的一位应聘者,工作4年26岁,统招本科。 以下就是他的简历和面试情况。 基本情况: 专业技能: 1、&nbsp;熟悉Sping了解SpringMVC、SpringBoot、Mybatis等框架、了解SpringCloud微服务 2、&nbsp;熟悉常用项目管理工具:SVN、GIT、MAVEN、Jenkins 3、&nbsp;熟悉Nginx、tomca...
2020年,冯唐49岁:我给20、30岁IT职场年轻人的建议
点击“技术领导力”关注∆每天早上8:30推送 作者|Mr.K 编辑| Emma 来源|技术领导力(ID:jishulingdaoli) 前天的推文《冯唐:职场人35岁以后,方法论比经验重要》,收到了不少读者的反馈,觉得挺受启发。其实,冯唐写了不少关于职场方面的文章,都挺不错的。可惜大家只记住了“春风十里不如你”、“如何避免成为油腻腻的中年人”等不那么正经的文章。 本文整理了冯...
程序员该看的几部电影
1、骇客帝国(1999) 概念:在线/离线,递归,循环,矩阵等 剧情简介: 不久的将来,网络黑客尼奥对这个看似正常的现实世界产生了怀疑。 他结识了黑客崔妮蒂,并见到了黑客组织的首领墨菲斯。 墨菲斯告诉他,现实世界其实是由一个名叫“母体”的计算机人工智能系统控制,人们就像他们饲养的动物,没有自由和思想,而尼奥就是能够拯救人类的救世主。 可是,救赎之路从来都不会一帆风顺,到底哪里才是真实的世界?如何...
Python绘图,圣诞树,花,爱心 | Turtle篇
每周每日,分享Python实战代码,入门资料,进阶资料,基础语法,爬虫,数据分析,web网站,机器学习,深度学习等等。 公众号回复【进群】沟通交流吧,QQ扫码进群学习吧 微信群 QQ群 1.画圣诞树 import turtle screen = turtle.Screen() screen.setup(800,600) circle = turtle.Turtle()...
作为一个程序员,CPU的这些硬核知识你必须会!
CPU对每个程序员来说,是个既熟悉又陌生的东西? 如果你只知道CPU是中央处理器的话,那可能对你并没有什么用,那么作为程序员的我们,必须要搞懂的就是CPU这家伙是如何运行的,尤其要搞懂它里面的寄存器是怎么一回事,因为这将让你从底层明白程序的运行机制。 随我一起,来好好认识下CPU这货吧 把CPU掰开来看 对于CPU来说,我们首先就要搞明白它是怎么回事,也就是它的内部构造,当然,CPU那么牛的一个东...
还记得那个提速8倍的IDEA插件吗?VS Code版本也发布啦!!
去年,阿里云发布了本地 IDE 插件 Cloud Toolkit,仅 IntelliJ IDEA 一个平台,就有 15 万以上的开发者进行了下载,体验了一键部署带来的开发便利。时隔一年的今天,阿里云正式发布了 Visual Studio Code 版本,全面覆盖前端开发者,帮助前端实现一键打包部署,让开发提速 8 倍。 VSCode 版本的插件,目前能做到什么? 安装插件之后,开发者可以立即体验...
破14亿,Python分析我国存在哪些人口危机!
一、背景 二、爬取数据 三、数据分析 1、总人口 2、男女人口比例 3、人口城镇化 4、人口增长率 5、人口老化(抚养比) 6、各省人口 7、世界人口 四、遇到的问题 遇到的问题 1、数据分页,需要获取从1949-2018年数据,观察到有近20年参数:LAST20,由此推测获取近70年的参数可设置为:LAST70 2、2019年数据没有放上去,可以手动添加上去 3、将数据进行 行列转换 4、列名...
2019年除夕夜的有感而发
天气:小雨(加小雪) 温度:3摄氏度 空气:严重污染(399) 风向:北风 风力:微风 现在是除夕夜晚上十点钟,再有两个小时就要新的一年了; 首先要说的是我没患病,至少现在是没有患病;但是心情确像患了病一样沉重; 现在这个时刻应该大部分家庭都在看春晚吧,或许一家人团团圆圆的坐在一起,或许因为某些特殊原因而不能团圆;但不管是身在何处,身处什么境地,我都想对每一个人说一句:新年快乐! 不知道csdn这...
听说想当黑客的都玩过这个Monyer游戏(1~14攻略)
第零关 进入传送门开始第0关(游戏链接) 请点击链接进入第1关: 连接在左边→ ←连接在右边 看不到啊。。。。(只能看到一堆大佬做完的留名,也能看到菜鸡的我,在后面~~) 直接fn+f12吧 &lt;span&gt;连接在左边→&lt;/span&gt; &lt;a href="first.php"&gt;&lt;/a&gt; &lt;span&gt;←连接在右边&lt;/span&gt; o...
在家远程办公效率低?那你一定要收好这个「在家办公」神器!
相信大家都已经收到国务院延长春节假期的消息,接下来,在家远程办公可能将会持续一段时间。 但是问题来了。远程办公不是人在电脑前就当坐班了,相反,对于沟通效率,文件协作,以及信息安全都有着极高的要求。有着非常多的挑战,比如: 1在异地互相不见面的会议上,如何提高沟通效率? 2文件之间的来往反馈如何做到及时性?如何保证信息安全? 3如何规划安排每天工作,以及如何进行成果验收? ...... ...
作为一个程序员,内存和磁盘的这些事情,你不得不知道啊!!!
截止目前,我已经分享了如下几篇文章: 一个程序在计算机中是如何运行的?超级干货!!! 作为一个程序员,CPU的这些硬核知识你必须会! 作为一个程序员,内存的这些硬核知识你必须懂! 这些知识可以说是我们之前都不太重视的基础知识,可能大家在上大学的时候都学习过了,但是嘞,当时由于老师讲解的没那么有趣,又加上这些知识本身就比较枯燥,所以嘞,大家当初几乎等于没学。 再说啦,学习这些,也看不出来有什么用啊!...
2020年的1月,我辞掉了我的第一份工作
其实,这篇文章,我应该早点写的,毕竟现在已经2月份了。不过一些其它原因,或者是我的惰性、还有一些迷茫的念头,让自己迟迟没有试着写一点东西,记录下,或者说是总结下自己前3年的工作上的经历、学习的过程。 我自己知道的,在写自己的博客方面,我的文笔很一般,非技术类的文章不想去写;另外我又是一个还比较热衷于技术的人,而平常复杂一点的东西,如果想写文章写的清楚点,是需要足够...
别低估自己的直觉,也别高估自己的智商
所有群全部吵翻天,朋友圈全部沦陷,公众号疯狂转发。这两周没怎么发原创,只发新闻,可能有人注意到了。我不是懒,是文章写了却没发,因为大家的关注力始终在这次的疫情上面,发了也没人看。当然,我...
这个世界上人真的分三六九等,你信吗?
偶然间,在知乎上看到一个问题 一时间,勾起了我深深的回忆。 以前在厂里打过两次工,做过家教,干过辅导班,做过中介。零下几度的晚上,贴过广告,满脸、满手地长冻疮。 再回首那段岁月,虽然苦,但让我学会了坚持和忍耐。让我明白了,在这个世界上,无论环境多么的恶劣,只要心存希望,星星之火,亦可燎原。 下文是原回答,希望能对你能有所启发。 如果我说,这个世界上人真的分三六九等,...
节后首个工作日,企业们集体开晨会让钉钉挂了
By 超神经场景描述:昨天 2 月 3 日,是大部分城市号召远程工作的第一天,全国有接近 2 亿人在家开始远程办公,钉钉上也有超过 1000 万家企业活跃起来。关键词:十一出行 人脸...
Java基础知识点梳理
虽然已经在实际工作中经常与java打交道,但是一直没系统地对java这门语言进行梳理和总结,掌握的知识也比较零散。恰好利用这段时间重新认识下java,并对一些常见的语法和知识点做个总结与回顾,一方面为了加深印象,方便后面查阅,一方面为了掌握好Android打下基础。
2020年全新Java学习路线图,含配套视频,学完即为中级Java程序员!!
新的一年来临,突如其来的疫情打破了平静的生活! 在家的你是否很无聊,如果无聊就来学习吧! 世上只有一种投资只赚不赔,那就是学习!!! 传智播客于2020年升级了Java学习线路图,硬核升级,免费放送! 学完你就是中级程序员,能更快一步找到工作! 一、Java基础 JavaSE基础是Java中级程序员的起点,是帮助你从小白到懂得编程的必经之路。 在Java基础板块中有6个子模块的学...
B 站上有哪些很好的学习资源?
哇说起B站,在小九眼里就是宝藏般的存在,放年假宅在家时一天刷6、7个小时不在话下,更别提今年的跨年晚会,我简直是跪着看完的!! 最早大家聚在在B站是为了追番,再后来我在上面刷欧美新歌和漂亮小姐姐的舞蹈视频,最近两年我和周围的朋友们已经把B站当作学习教室了,而且学习成本还免费,真是个励志的好平台ヽ(.◕ฺˇд ˇ◕ฺ;)ノ 下面我们就来盘点一下B站上优质的学习资源: 综合类 Oeasy: 综合...
如何优雅地打印一个Java对象?
你好呀,我是沉默王二,一个和黄家驹一样身高,和刘德华一样颜值的程序员。虽然已经写了十多年的 Java 代码,但仍然觉得自己是个菜鸟(请允许我惭愧一下)。 在一个月黑风高的夜晚,我思前想后,觉得再也不能这么蹉跎下去了。于是痛下决心,准备通过输出的方式倒逼输入,以此来修炼自己的内功,从而进阶成为一名真正意义上的大神。与此同时,希望这些文章能够帮助到更多的读者,让大家在学习的路上不再寂寞、空虚和冷。 ...
雷火神山直播超两亿,Web播放器事件监听是怎么实现的?
Web播放器解决了在手机浏览器和PC浏览器上播放音视频数据的问题,让视音频内容可以不依赖用户安装App,就能进行播放以及在社交平台进行传播。在视频业务大数据平台中,播放数据的统计分析非常重要,所以Web播放器在使用过程中,需要对其内部的数据进行收集并上报至服务端,此时,就需要对发生在其内部的一些播放行为进行事件监听。 那么Web播放器事件监听是怎么实现的呢? 01 监听事件明细表 名...
相关热词 c# 为空 判断 委托 c#记事本颜色 c# 系统默认声音 js中调用c#方法参数 c#引入dll文件报错 c#根据名称实例化 c#从邮件服务器获取邮件 c# 保存文件夹 c#代码打包引用 c# 压缩效率
立即提问