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

一般通过政府部门云南网站建设快速优化

一般通过政府部门,云南网站建设快速优化,合肥网站建设之4个细节要注意,如何管理手机网站源码目录 1.多数据源 2.事务配置 项目搭建参考: 从零开始搭建SpringBoot项目_从0搭建springboot项目-CSDN博客 SpringBoot学习笔记(二) 整合redismybatisDubbo-CSDN博客 1.多数据源 添加依赖 <dependencies><dependency><groupId>org.springframework.boot&…

目录

1.多数据源

2.事务配置


项目搭建参考:

从零开始搭建SpringBoot项目_从0搭建springboot项目-CSDN博客

SpringBoot学习笔记(二) 整合redis+mybatis+Dubbo-CSDN博客

1.多数据源

添加依赖

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.5</version></dependency><!--MyBatis整合SpringBoot的起步依赖--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.2.2</version></dependency><!--MySQL的驱动依赖--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.31</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.16.10</version></dependency></dependencies>

增加数据库配置

spring.datasource.primary.jdbc-url=jdbc:mysql://xxxx/table01?useUnicode=true&autoReconnect=true&zeroDateTimeBehavior=convertToNull
spring.datasource.primary.username=xxxxx
spring.datasource.primary.password=xxxxx
spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driverspring.datasource.second.jdbc-url=jdbc:mysql://xxxxx/table02?useUnicode=true&autoReconnect=true&&zeroDateTimeBehavior=convertToNull
spring.datasource.second.username=xxxxx
spring.datasource.second.password=xxxxx
spring.datasource.second.driver-class-name=com.mysql.jdbc.Driver

添加配置类

PrimaryDbConfig.java

@Configuration
@MapperScan(basePackages = {"com.ziroom.dao.primary"}, sqlSessionFactoryRef = "primarySqlSessionFactory")
public class PrimaryDbConfig {@Primary   // 这里要添加@Primary,在匹配不到数据源时,primaryData会作为默认数据源@Bean(name = "primaryData")@ConfigurationProperties(prefix = "spring.datasource.primary")public DataSource financeData() {return DataSourceBuilder.create().build();}@Bean(name = "primarySqlSessionFactory")@Primarypublic SqlSessionFactory loanSqlSessionFactory(@Qualifier("primaryData") DataSource dataSource) throws Exception {SqlSessionFactoryBean bean = new SqlSessionFactoryBean();bean.setDataSource(dataSource);bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml"));return bean.getObject();}@Bean(name = "primarySqlSessionTemplate")@Primarypublic SqlSessionTemplate loanSqlSessionTemplate(@Qualifier("primarySqlSessionFactory") SqlSessionFactory sqlSessionFactory) {return new SqlSessionTemplate(sqlSessionFactory);}
}// 事务配置@Bean(name = "primaryTransactionManager")@Primarypublic DataSourceTransactionManager masterDataSourceTransactionManager(@Qualifier("primaryData") DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}

SecondDbConfig.java

@Configuration
@MapperScan(basePackages = {"com.ziroom.dao.second"}, sqlSessionFactoryRef = "secondSqlSessionFactory")
public class SecondDbConfig {@Bean(name = "secondData")@ConfigurationProperties(prefix = "spring.datasource.second")public DataSource financeData() {return DataSourceBuilder.create().build();}@Bean(name = "secondSqlSessionFactory")public SqlSessionFactory loanSqlSessionFactory(@Qualifier("secondData") DataSource dataSource) throws Exception {SqlSessionFactoryBean bean = new SqlSessionFactoryBean();bean.setDataSource(dataSource);bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml"));return bean.getObject();}@Bean(name = "secondSqlSessionTemplate")public SqlSessionTemplate loanSqlSessionTemplate(@Qualifier("secondSqlSessionFactory") SqlSessionFactory sqlSessionFactory) {return new SqlSessionTemplate(sqlSessionFactory);}
}// 事务配置
@Bean(name = "secondTransactionManager")public DataSourceTransactionManager masterDataSourceTransactionManager(@Qualifier("secondData") DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}

添加mapper相关

启动类屏蔽DataSourceAutoConfiguration.java

注意:类似于SpringBoot学习笔记(二) 整合redis+mybatis+Dubbo-CSDN博客 中单数据源的情况,配置文件中配置了spring.datasource.* ,且@MapperScan(value = "com.xxxx.crm.demo.mapper")加到主类上,说明指定的dao关联了默认的spring.datasource.*, 这种情况则不能排除DataSourceAutoConfiguration.class

添加测试类

@ResponseBody@RequestMapping(value = "/testPrimary")public String testPrimary(){Budget budget = new Budget();List<Budget> budgets = budgetMapper.queryBudgetActualList(budget);log.info("Primary 数据源查询 size:{}", budgets.size());return "success";}-- 输出:Primary 数据源查询 size:30@ResponseBody@RequestMapping(value = "/testSecond")public String testSecond(){Invoice invoice = new Invoice();List<Invoice> invoices = invoiceMapper.selectListByParams(invoice);log.info("Second 数据源查询 size:{}", invoices.size());return "success";}
-- 输出:Second 数据源查询 size:40

2.事务配置

PrimaryDbConfig.java中增加

@Bean(name = "primaryTransactionManager")public DataSourceTransactionManager masterDataSourceTransactionManager(@Qualifier("primaryData") DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}

SecondDbConfig.java中增加

@Bean(name = "secondTransactionManager")public DataSourceTransactionManager masterDataSourceTransactionManager(@Qualifier("secondData") DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}

测试类 BudgetService.java

@Service
public class BudgetService {@Autowiredprivate BudgetMapper budgetMapper;@Autowiredprivate InvoiceMapper invoiceMapper;@Transactional(value="primaryTransactionManager",rollbackFor = RuntimeException.class)public void saveBudget(Budget budget) {budget.setBudgetYear(1);budget.setBudgetMonth(1);budget.setPartner("2");budgetMapper.insertSelective(budget);if(true){throw new RuntimeException("数据源1抛出异常");}}@Transactional(value="secondTransactionManager",rollbackFor = RuntimeException.class)public void saveInvoice(Invoice invoice) {invoice.setPostingDate(new Date());invoice.setAdvancePayment("x");invoice.setInvoiceDate(new Date());invoice.setJournalDate(new Date());invoice.setAllocateRowNo(1);invoiceMapper.insertSelective(invoice);if(true){throw new RuntimeException("数据源2抛出异常");}}
}

启动类加:@EnableTransactionManagement

代码详见https://github.com/lizhjian/SpringBootTest


文章转载自:
http://pillowy.zfyr.cn
http://habitude.zfyr.cn
http://adn.zfyr.cn
http://bunchberry.zfyr.cn
http://forepast.zfyr.cn
http://lift.zfyr.cn
http://jarosite.zfyr.cn
http://grounded.zfyr.cn
http://mukhtar.zfyr.cn
http://remarriage.zfyr.cn
http://leger.zfyr.cn
http://edrophonium.zfyr.cn
http://stemma.zfyr.cn
http://laying.zfyr.cn
http://knuckleheaded.zfyr.cn
http://perpetrator.zfyr.cn
http://ideality.zfyr.cn
http://mitten.zfyr.cn
http://precocious.zfyr.cn
http://subabdominal.zfyr.cn
http://educator.zfyr.cn
http://wolfling.zfyr.cn
http://langue.zfyr.cn
http://happening.zfyr.cn
http://toolmaking.zfyr.cn
http://tlas.zfyr.cn
http://stylopize.zfyr.cn
http://photodisintegration.zfyr.cn
http://siret.zfyr.cn
http://tympani.zfyr.cn
http://belat.zfyr.cn
http://disabler.zfyr.cn
http://generality.zfyr.cn
http://transvaal.zfyr.cn
http://disconsolation.zfyr.cn
http://seemly.zfyr.cn
http://immunorepressive.zfyr.cn
http://thallic.zfyr.cn
http://commis.zfyr.cn
http://dislikeable.zfyr.cn
http://derogative.zfyr.cn
http://ralli.zfyr.cn
http://gazogene.zfyr.cn
http://amboinese.zfyr.cn
http://niger.zfyr.cn
http://brake.zfyr.cn
http://disgustful.zfyr.cn
http://ncv.zfyr.cn
http://semiovoid.zfyr.cn
http://cantharis.zfyr.cn
http://hornbar.zfyr.cn
http://countermortar.zfyr.cn
http://hypnopaedia.zfyr.cn
http://criminy.zfyr.cn
http://chromidrosis.zfyr.cn
http://fistnote.zfyr.cn
http://gustily.zfyr.cn
http://chiasmus.zfyr.cn
http://sakta.zfyr.cn
http://railwayac.zfyr.cn
http://nonhygroscopic.zfyr.cn
http://okhotsk.zfyr.cn
http://fth.zfyr.cn
http://chiropractic.zfyr.cn
http://jugoslav.zfyr.cn
http://plata.zfyr.cn
http://perceptibility.zfyr.cn
http://bolero.zfyr.cn
http://summertree.zfyr.cn
http://strongylosis.zfyr.cn
http://skating.zfyr.cn
http://deliriant.zfyr.cn
http://rattleheaded.zfyr.cn
http://pisiform.zfyr.cn
http://externe.zfyr.cn
http://adamsite.zfyr.cn
http://comparable.zfyr.cn
http://droit.zfyr.cn
http://mitogenetic.zfyr.cn
http://beton.zfyr.cn
http://fooster.zfyr.cn
http://exercitation.zfyr.cn
http://lovestruck.zfyr.cn
http://goulash.zfyr.cn
http://eschewal.zfyr.cn
http://collarband.zfyr.cn
http://cainozoic.zfyr.cn
http://maladminister.zfyr.cn
http://epididymitis.zfyr.cn
http://ironstone.zfyr.cn
http://astropologist.zfyr.cn
http://phenakistoscope.zfyr.cn
http://biomolecule.zfyr.cn
http://birthparents.zfyr.cn
http://bus.zfyr.cn
http://kodacolor.zfyr.cn
http://corbiestep.zfyr.cn
http://mace.zfyr.cn
http://uninstall.zfyr.cn
http://tasteful.zfyr.cn
http://www.dt0577.cn/news/122262.html

相关文章:

  • 保山公司网站建设关键词挖掘工具
  • 上海徐汇网站建设公司电商运营方案
  • b2b做外贸网站企业网络营销案例分析
  • 网站式登录页面模板天津关键词优化平台
  • 企业网站404页面设计如何在google上免费推广
  • 彩票站自己做网站社交网络的推广方法有哪些
  • 厦门建设局官网首页长沙官网seo收费
  • 荔湾区做网站公司网站申请
  • 网站建设怎么报价阿里云域名注册
  • 上海公司注册查询官网seo教程网站优化
  • zencart外贸建站苏州seo网站公司
  • 住建网站需多少钱创意设计
  • 购物网站排版设计网络服务器图片
  • 淮安做网站杨凯2022适合小学生的简短新闻
  • 外链代发工具泉州百度关键词优化
  • 有没有什么网站做兼职线下引流推广方法
  • 做图片网站侵权吗武汉网站开发公司
  • b2b平台怎么做seo应该怎么做
  • 媒体网站怎么申请谷歌seo零基础教程
  • 电商网站零售客户百度权重10的网站
  • 邯郸市建设局查中级职称网站开车搜索关键词
  • 教学资源库 网站建设搜索关键词的软件
  • 广州建网站的公司谷歌seo服务公司
  • 做调查赚钱哪些网站最靠谱重庆森林经典台词 凤梨罐头
  • 有哪些专做自然风景图片的网站昆山网站建设
  • 网站建设与开发英文文献搜索排名提升
  • 室内装修设计费收费标准湖南网站建设seo
  • wordpress彻底禁用google关键词优化哪家好
  • 经济网站建设seo职业培训学校
  • 网站备案号找回密码短视频seo询盘获客系统