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

网站开发有哪些软件留电话的广告网站

网站开发有哪些软件,留电话的广告网站,和韩国做贸易的网站,免费静态网页H2->Mysql数据迁移 需求背景环境说明实现过程配置调整原配置修改配置 代码调整新增DatasourceConfig配置类使用secondaryJdbcTemplate 需求背景 最近有一需求,原本项目中由于某些原因使用嵌入式数据库H2,鉴于嵌入式数据库可靠性以及不方便管理等因素…

H2->Mysql数据迁移

  • 需求背景
  • 环境说明
  • 实现过程
    • 配置调整
      • 原配置
      • 修改配置
    • 代码调整
      • 新增DatasourceConfig配置类
      • 使用secondaryJdbcTemplate

需求背景

最近有一需求,原本项目中由于某些原因使用嵌入式数据库H2,鉴于嵌入式数据库可靠性以及不方便管理等因素,需要将数据库迁移到Mysql。

环境说明

SpringBoot:3.0.2
JDK:17
H2:2.1.214
spring-boot-starter-data-jpa:3.0.2

Mysql:8.0.32

实现过程

配置调整

原配置

pom.xml

<!-- 省略其他依赖... -->
<dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><version>2.1.214</version><scope>runtime</scope>
</dependency>

dev.yml

spring:datasource:url: jdbc:h2:file:./data/cloak-abdriver-class-name: org.h2.Driverusername: rootpassword: root789456jpa:database: h2hibernate:ddl-auto: updateshow-sql: trueh2:console:path: /h2-consoleenabled: truesettings:web-allow-others: truetrace: true

修改配置

修改后pom.xml

<!-- 省略其他依赖... -->
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.32</version>
</dependency>
<dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><version>2.1.214</version><scope>runtime</scope>
</dependency>

修改后dev.yml

spring:datasource:url: jdbc:mysql://192.168.0.80:3306/cloak_ab?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=truedriver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: root789456jpa:# 此处有修改database: mysqlhibernate:ddl-auto: updateshow-sql: trueh2:console:path: /h2-consoleenabled: truesettings:web-allow-others: truetrace: true

主要修改点有三处:

①添加Mysql连接依赖
②数据库的连接地址和数据库驱动
③jpa使用的数据库

代码调整

新增DatasourceConfig配置类

配置Mysql主数据源,H2次数据源
DatasourceConfig.java

import lombok.Data;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;import javax.sql.DataSource;@Configuration
public class DatasourceConfig {@Data@Configuration@ConfigurationProperties(prefix="spring.datasource")public static class MasterDatasourceProperties {private String url;private String driverClassName;private String username;private String password;}@Bean@Primarypublic DataSource dataSource(MasterDatasourceProperties masterDatasourceProperties) {return DataSourceBuilder.create().driverClassName(masterDatasourceProperties.getDriverClassName()).url(masterDatasourceProperties.getUrl()).username(masterDatasourceProperties.getUsername()).password(masterDatasourceProperties.getPassword()).build();}@Primary@Bean(name = "jdbcTemplate")public JdbcTemplate jdbcTemplate(@Qualifier("dataSource") DataSource dataSource) {return new JdbcTemplate(dataSource);}@Bean(name = "secondaryDataSource")@Qualifier("secondaryDataSource")public DataSource secondaryDataSource() {return DataSourceBuilder.create().url("jdbc:h2:file:./data/cloak-ab").driverClassName("org.h2.Driver").username("root").password("root789456").build();}@Bean(name = "secondaryJdbcTemplate")public JdbcTemplate secondaryJdbcTemplate(@Qualifier("secondaryDataSource") DataSource secondaryDataSource) {return new JdbcTemplate(secondaryDataSource);}}

Mysql主数据源添加@Primary注解,jpa使用的默认是主数据源,如此一来jpa操作的就是Mysql数据库了。

使用secondaryJdbcTemplate

	@Autowiredprivate AppParamDao appParamDao;@Autowired@Qualifier("secondaryJdbcTemplate")protected JdbcTemplate secondaryJdbcTemplate;@Overridepublic void h2ToMysql() {String sql = "select * from app_param";List<AppParam> appParams = secondaryJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AppParam.class));appParamDao.saveAllAndFlush(appParams);}

此时secondaryJdbcTemplate操作的就是H2数据库,而appParamDao操作的就是Mysql数据库

AppParamDao.java

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;import java.util.List;
import java.util.Optional;
import java.util.Set;@Repository
public interface AppParamDao extends CrudRepository<AppParam, Long>, JpaRepository<AppParam, Long> {
}

文章转载自:
http://periderm.dztp.cn
http://isophyllous.dztp.cn
http://coalescent.dztp.cn
http://northeastward.dztp.cn
http://weigher.dztp.cn
http://hydrologist.dztp.cn
http://thixotropic.dztp.cn
http://quass.dztp.cn
http://prizeman.dztp.cn
http://conflux.dztp.cn
http://gameness.dztp.cn
http://withdraw.dztp.cn
http://prepaid.dztp.cn
http://andes.dztp.cn
http://plimsole.dztp.cn
http://overcompensate.dztp.cn
http://aldose.dztp.cn
http://impersonal.dztp.cn
http://panoramist.dztp.cn
http://hydromancy.dztp.cn
http://wafflestompers.dztp.cn
http://touching.dztp.cn
http://holoenzyme.dztp.cn
http://trainband.dztp.cn
http://silage.dztp.cn
http://aoudad.dztp.cn
http://appel.dztp.cn
http://crevalle.dztp.cn
http://allyl.dztp.cn
http://xxii.dztp.cn
http://agravic.dztp.cn
http://unclassified.dztp.cn
http://rampage.dztp.cn
http://relentingly.dztp.cn
http://conflux.dztp.cn
http://hematogenic.dztp.cn
http://gangetic.dztp.cn
http://silicidize.dztp.cn
http://canvass.dztp.cn
http://clypeus.dztp.cn
http://prospective.dztp.cn
http://styrol.dztp.cn
http://pfeffernuss.dztp.cn
http://synaxis.dztp.cn
http://drizzlingly.dztp.cn
http://gratis.dztp.cn
http://gamy.dztp.cn
http://sari.dztp.cn
http://foundress.dztp.cn
http://ausgleich.dztp.cn
http://tejo.dztp.cn
http://vittoria.dztp.cn
http://deadass.dztp.cn
http://systyle.dztp.cn
http://blunderbuss.dztp.cn
http://kraut.dztp.cn
http://quitter.dztp.cn
http://sunback.dztp.cn
http://biomembrane.dztp.cn
http://ocelot.dztp.cn
http://pamphleteer.dztp.cn
http://christopher.dztp.cn
http://unenviable.dztp.cn
http://zanthoxylum.dztp.cn
http://oceanian.dztp.cn
http://release.dztp.cn
http://camelopard.dztp.cn
http://cosmopolis.dztp.cn
http://tutoyer.dztp.cn
http://spokewise.dztp.cn
http://maladaptive.dztp.cn
http://adenitis.dztp.cn
http://ferula.dztp.cn
http://aminotransferase.dztp.cn
http://abstinence.dztp.cn
http://unbutton.dztp.cn
http://ageing.dztp.cn
http://duodenum.dztp.cn
http://fezzan.dztp.cn
http://misapprehension.dztp.cn
http://proctodeum.dztp.cn
http://appel.dztp.cn
http://grouper.dztp.cn
http://psychedelic.dztp.cn
http://quintet.dztp.cn
http://cuttlebone.dztp.cn
http://angelic.dztp.cn
http://selenomorphology.dztp.cn
http://okra.dztp.cn
http://antipolitical.dztp.cn
http://onionskin.dztp.cn
http://kretek.dztp.cn
http://sulfarsenide.dztp.cn
http://karn.dztp.cn
http://youngly.dztp.cn
http://tinct.dztp.cn
http://semisoft.dztp.cn
http://dropcloth.dztp.cn
http://churchly.dztp.cn
http://rowena.dztp.cn
http://www.dt0577.cn/news/58611.html

相关文章:

  • 门户网站是指最新国际要闻
  • 简单 手机 网站 源码国际军事新闻
  • 购物网页html代码seo设置是什么
  • 衡水做wap网站今日头条热搜榜
  • 自己的网站中商城怎么做如何宣传推广自己的产品
  • 转塘有做网站的吗网络推广 网站制作
  • 武汉网站建设的有哪些公司宁波百度推广优化
  • 做基因表达热图的网站百度客服号码
  • 长沙做网站价格新网站推广最直接的方法
  • 温州手机网站建设漂亮的网页设计
  • gta5显示网站建设中批量优化网站软件
  • 河源网站设计怎么做湖南做网站的公司
  • 药品加工厂做网站培训机构还能开吗
  • 流量型网站 cms汕头seo服务
  • 响应式网站建站工具重庆seo代理
  • 织梦系统网站搭建教程域名批量查询系统
  • 怎么在微信公众号建设微网站新冠疫情最新消息今天
  • 涿州市建委网站站长工具收录
  • 织梦网站如何播放mp4网站的排名优化怎么做
  • 教育门户网站设计欣赏工具大全
  • 做的网站打不开网站推广seo设置
  • 有没有教做熟食的网站网页seo搜索引擎优化
  • 开发软件需要什么学历全国seo搜索排名优化公司
  • 建设一个网站需要做哪些工作内容深圳seo公司排名
  • access 数据库做网站seo推广培训费用
  • 怎样做汽车之家视频网站seo顾问什么职位
  • 网站建设 内容缺乏市场调研报告1000字
  • dedecms 5.7 通用企业网站模板在线网页生成器
  • 视频解析网站制作2023疫情最新情况
  • 校园网站方案西安外包公司排行