当前位置: 首页 > news >正文

湖南seo网站策划校园文化建设网站

湖南seo网站策划,校园文化建设网站,一键生成个人网站,如何做好网络销售spring 多数据源配置spring 多数据源配置一般有两种方案#xff1a;1、在spring项目启动的时候直接配置两个不同的数据源#xff0c;不同的sessionFactory。在dao 层根据不同业务自行选择使用哪个数据源的session来操作。2、配置多个不同的数据源#xff0c;使用一个session…spring 多数据源配置spring 多数据源配置一般有两种方案1、在spring项目启动的时候直接配置两个不同的数据源不同的sessionFactory。在dao 层根据不同业务自行选择使用哪个数据源的session来操作。2、配置多个不同的数据源使用一个sessionFactory,在业务逻辑使用的时候自动切换到不同的数据源有一个种是在拦截器里面根据不同的业务现切换到不同的datasource;有的会在业务层根据业务来自动切换。但这种方案在多线程并发的时候会出现一些问题需要使用threadlocal等技术来实现多线程竞争切换数据源的问题。【本文暂时只讨论第一种方案】spring多事务配置主要体现在db配置这块配置不同的数据源和不同的session1、一下贴出 spring-db.xml配置xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd2、dao层做了一个小的封装将不同的SqlSessionFactory 注入到 SessionFactory通过BaseDao来做简单的封装封装不同库的基本增删改。dao实现层都集成于Basedao 这样的话实现可以根据自己需要来选择不同的库来操作不同的内容。session工厂package com.neo.dao;import com.neo.entity.Entity;public class BaseDao extends SessionFactory{public void test1Update(Entity entity) {this.getTest1Session().update(entity.getClass().getSimpleName().update, entity);}public void test2Update(Entity entity) {this.getTest2Session().update(entity.getClass().getSimpleName().update, entity);}}BaseDaopackage com.neo.dao;import com.neo.entity.Entity;public class BaseDao extends SessionFactory{public void test1Update(Entity entity) {this.getTest1Session().update(entity.getClass().getSimpleName().update, entity);}public void test2Update(Entity entity) {this.getTest2Session().update(entity.getClass().getSimpleName().update, entity);}}以上的配置在多数据源连接正常的增删改都是没有问题的但是遇到分布式的事务是就出问题测试代码package com.neo.service.impl;import javax.annotation.Resource;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;import com.neo.dao.UserDao;import com.neo.dao.UserInformationsDao;import com.neo.entity.UserEntity;import com.neo.entity.UserInformationsEntity;import com.neo.service.UserService;Servicepublic class UserServiceImpl implements UserService {Resource UserDao userDao;Resource UserInformationsDao userInformationsDao;OverrideTransactionalpublic void updateUserinfo() {UserEntity usernew UserEntity();user.setId(1);user.setUserName(李四4);UserInformationsEntity userInfonew UserInformationsEntity();userInfo.setUserId(1);userInfo.setAddress(陕西4);userDao.updateUser(user);userInformationsDao.updateUserInformations(userInfo);if(true){throw new RuntimeException(test tx );}}}在service添加事务后更新完毕抛出异常test2更新进行了回滚test1 数据更新没有回滚。解决方案添加分布式的事务Atomikos和spring结合来处理。Atomikos多数据源的配置xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd${database.test1.url}${database.test1.username}${database.test1.password}${database.test2.url}${database.test2.username}${database.test2.password}所有代码请参考这里https://github.com/ityouknow/spring-examples
http://www.yutouwan.com/news/459253/

相关文章:

  • wordpress的网站白云区最新新闻
  • 手机产品展示网站模板直缝钢管网站建设
  • 宁波网站建设yiso汽车之家网页版入口
  • 郑州 科技有限公司 网站建设网站生成器下载
  • 企业网站数据库有经验的坪山网站建设
  • wordpress站点进入时弹窗婚嫁网站建设计划
  • 企业网站seo分析徽文化网站建设方案书
  • 专做hip hop音乐的网站怎样辨别自己网站的好坏
  • 做网站后端建行官网个人登录
  • 阿里云服务器wordpress建站教程做淘宝券推广的网站有哪些
  • 丹灶网站建设胶南网站建设
  • 高新区免费网站建设上海网站推广优化
  • 青岛网站建设哪个平台好把wordpress装进app
  • 用境外服务器做网站发卡网站建设
  • 无锡阳山镇网站建设网络营销方式包括哪些
  • 能用网站做微信小程序上海刚刚宣布
  • 网站备案号添加超链接网站空间没有续费
  • 网站后台登录界面代码推广型网站建设地址
  • 贵阳装饰装修公司网站wordpress 换页面
  • 微信打不开网站武安市网站建设费用
  • 新手可以自己学做网站设计吗为学校网站做网站推广策划
  • p2p理财网站开发框架如何做网站首页收录
  • 关键词小说台州网站建设方案优化
  • 山东平台网站建设方案广告设计服务
  • 定制手机壳的网站星凯网站建设
  • 做重视频网站界面设计图片 作品
  • 中网可信网站查询建设部监理师网站
  • 网站托管怎么做等保网页制作代码成品
  • 国家优质校建设网站wordpress 5.0.2关键词设置
  • 电子商务网站建设步骤百度文库两个网站做的h5如何合在一起