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

东莞营销网站建设多少钱wordpress定时发布功能

东莞营销网站建设多少钱,wordpress定时发布功能,自己能否建设网站,网站开发总体功能设计Spring Boot应用中集成与使用多数据源 1. 前言 通过定义和使用多个数据源#xff0c;能在Spring Boot应用中实现更复杂的数据管理场景#xff0c;比如读写分离、数据冗余等。 2. 准备工作 环境准备#xff1a;确保已经准备好Spring Boot的开发环境。数据库准备#xff…Spring Boot应用中集成与使用多数据源 1. 前言 通过定义和使用多个数据源能在Spring Boot应用中实现更复杂的数据管理场景比如读写分离、数据冗余等。 2. 准备工作 环境准备确保已经准备好Spring Boot的开发环境。数据库准备在本地或云服务上创建两个数据库如下文所示。 3. 创建Spring Boot项目 使用Spring Initializr创建项目https://start.spring.io/。在pom.xml中添加必要的依赖包括JPA、Spring Boot Parent、数据库驱动等。 4. 配置多数据源 在application.yml或application.properties中配置 # application.yml spring:datasource:primary:url: jdbc:mysql://localhost:3306/db1username: userpassword: passworddriver-class-name: com.mysql.jdbc.Driverhikari:connection-timeout: 30000maximum-pool-size: 20secondary:url: jdbc:mysql://localhost:3306/db2username: userpassword: passworddriver-class-name: com.mysql.jdbc.Driverhikari:connection-timeout: 30000maximum-pool-size: 205. 创建实体类及Repository Entity Class - User (For Primary Database): package com.example.multidatasource.entity;import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table;Entity Table(name users) public class User {Idprivate Long id;private String name;private String email;// getter, setter, constructors }Entity Class - Product (For Secondary Database): package com.example.multidatasource.entity;import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table;Entity Table(name products) public class Product {Idprivate Long id;private String name;private int price;// getter, setter, constructors }Repository (Primary): package com.example.multidatasource.repository;import com.example.multidatasource.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository;Repository public interface UserRepository extends JpaRepositoryUser, Long { }Repository (Secondary): package com.example.multidatasource.repository;import com.example.multidatasource.entity.Product; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository;Repository public interface ProductRepository extends JpaRepositoryProduct, Long { }6. 服务层配置与使用多数据源 package com.example.multidatasource.service;import com.example.multidatasource.entity.Product; import com.example.multidatasource.repository.ProductRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;Service public class ProductService {private final ProductRepository productRepository;Autowiredpublic ProductService(ProductRepository productRepository) {this.productRepository productRepository;}public Product createProduct(String name, int price) {Product product new Product();product.setName(name);product.setPrice(price);return productRepository.save(product);} }服务层同样应当遵循具体数据源的配置确保通过合适的数据源进行持久化操作。 7. 事务与多数据源管理 针对跨数据源的事务操作需要在Service中配置Transactional注解 Service public class MultiDataSourceTransactionService {private final UserRepository userRepository;private final ProductRepository productRepository;Autowiredpublic MultiDataSourceTransactionService(UserRepository userRepository, ProductRepository productRepository) {this.userRepository userRepository;this.productRepository productRepository;}// So that its only using the primary dataSourceTransactional(propagation Propagation.REQUIRED)public void performCreateUserAndProduct() {userRepository.save(new User(John Doe, johnexample.com));productRepository.save(new Product(Widget, 1000));} }通过这种方式可以确保同一个请求中的所有操作要么全部成功要么全部回滚。 8. 配置及测试 确保所有的Bean和配置类被正确注解测试应用是否能够启动数据源是否能够正确读写数据。
http://www.w-s-a.com/news/828559/

相关文章:

  • 南通网站搜索引擎优化网站首页seo关键词布局
  • 东莞市国外网站建设多少钱wordpress 多媒体插件
  • c2c商城网站建设公司做水果生意去哪个网站
  • 做网站服务器有哪些电子商务网站建立
  • 网站开发的具体流程原材料价格查询网站
  • 深圳响应式网站建设深圳网站建设定制开发 超凡科技
  • 网站建设报价怎么差别那么大wordpress产品属性搭配
  • 高校网站建设情况报告范文pc建站网站
  • 做网站美工要学什么广东省建设厅网站首页
  • 深圳网站设计十年乐云seo网站建设 竞赛 方案
  • 新乡移动网站建设wordpress输出某一分类的文章
  • 花店网站开发设计的项目结构重庆网站建设培训班
  • 做网站的技术体系投资者互动平台官网
  • 北京网站建设公司哪家实惠企查查在线查询入口
  • 毕业设计做网站怎么样非微信官方网页自己做的网站
  • 昆明网站多端小程序设计重庆市住房和城乡建设厅网站
  • 网站制作技术人员国际新闻最新10条
  • 做同城特价的网站wordpress后台能修改模板文件
  • 网站信息可以边建设边组织产品展示网站源码php
  • 电子商务网站规划从哪些方面入手途牛企业网站建设方案
  • 莱阳网站定制易语言可以做网站嘛
  • 购物网站开发意义上海中小企业服务中心官网
  • 网站备案证书如何打开江苏网站建设电话
  • 深圳网站建设乐云seo搜索引擎优化seo目的
  • 中山城市建设集团网站网站建设设计基础
  • 网站开发流程莆田wordpress点播收费
  • 网站未及时续费浙江台州做网站的公司有哪些
  • 二级域名做网站好不好河源建网站
  • 公司网站的作用意义维护建设管理天津平台网站建设费用
  • 建设部网站如何下载国标规范上海影视公司