国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

spring boot下基于spring data jpa配置mysql+達夢多數(shù)據(jù)源(以不同包路徑方式,mysql為主數(shù)據(jù)源)

這篇具有很好參考價值的文章主要介紹了spring boot下基于spring data jpa配置mysql+達夢多數(shù)據(jù)源(以不同包路徑方式,mysql為主數(shù)據(jù)源)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。


關(guān)鍵詞:mysql 達夢/dameng jpa 多數(shù)據(jù)源

版本信息/主要引包信息

spring boot:2.1.17.RELEASE
mysql驅(qū)動:8.0.21(跟隨boot版本)
達夢驅(qū)動:8.1.2.192
lombok:1.18.12(跟隨boot版本)

背景概述

  • 以mysql為主數(shù)據(jù)源,達夢為第二數(shù)據(jù)源方式配置
  • 適用于舊項目二次開發(fā)接入達夢數(shù)據(jù)庫或基于通用二方/三方包做業(yè)務(wù)擴展等場景
  • 將以不同包路徑方式綁定不同數(shù)據(jù)源,以便擴展

代碼示例

  • 其中,primary為主數(shù)據(jù)源,second為第二數(shù)據(jù)源

引包部分(pom.xml)

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>org</groupId>
	<artifactId>test-jpa-tra</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>test-jpa-tra</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
		<spring-boot.version>2.1.17.RELEASE</spring-boot.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
		</dependency>
		<!-- 數(shù)據(jù)庫驅(qū)動 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>com.dameng</groupId>
			<artifactId>DmJdbcDriver18</artifactId>
			<version>8.1.2.192</version>
		</dependency>
		<dependency>
			<groupId>com.dameng</groupId>
			<artifactId>DmDialect-for-hibernate5.3</artifactId>
			<version>8.1.2.192</version>
		</dependency>
	</dependencies>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-dependencies</artifactId>
				<version>${spring-boot.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

實體部分(Entity)

主數(shù)據(jù)源:

package org.test.data.entity.primary;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@ToString(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "test")
public class Test {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	private String name;
}

第二數(shù)據(jù)源:

package org.test.data.entity.second;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@ToString(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "test2")
public class Test2 {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	private String name;
}

數(shù)據(jù)庫接口部分(Repository)

主數(shù)據(jù)源:

package org.test.dao.primary;

import org.springframework.stereotype.Repository;
import org.test.data.entity.primary.Test;

import org.springframework.data.jpa.repository.JpaRepository;

@Repository
public interface TestRepository extends JpaRepository<Test, Integer> {
}

第二數(shù)據(jù)源:

package org.test.dao.second;

import org.springframework.stereotype.Repository;
import org.test.data.entity.second.Test2;

import org.springframework.data.jpa.repository.JpaRepository;

@Repository
public interface TestRepository2 extends JpaRepository<Test2, Integer> {
}

服務(wù)接口部分(Service)

此處略,可按實際項目關(guān)聯(lián),服務(wù)部分可無需區(qū)分包路徑

配置部分(Configuration)

此處將配置數(shù)據(jù)庫配置讀取數(shù)據(jù)源、EntityManager構(gòu)造工廠以及事務(wù)管理器
主數(shù)據(jù)源:

package org.test.property.config;

import java.util.HashMap;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.util.StringUtils;

import com.zaxxer.hikari.HikariDataSource;

@Configuration
@EnableTransactionManagement // 開啟事務(wù)
@EnableJpaRepositories(basePackages = { "org.test.dao.primary" },
		entityManagerFactoryRef = "primaryEntityManagerFactory", 
		transactionManagerRef = "primaryTransactionManager" 
)
public class TestPrimaryDataSourceConfig {
	/**
	 * 指定 primary 數(shù)據(jù)源的 dataSource 配置
	 *
	 * @return primary 數(shù)據(jù)源配置
	 */
	@Primary
	@Bean(name = "primaryDataSourceProperties")
	@ConfigurationProperties("spring.datasource.primary") 
	public DataSourceProperties dataSourceProperties() {
		return new DataSourceProperties();
	}

	/**
	 * 可以選擇不同的數(shù)據(jù)源,這?使? HikariDataSource,創(chuàng)建數(shù)據(jù)源
	 *
	 * @param primaryDataSourceProperties
	 *            數(shù)據(jù)源配置
	 * @return primary 數(shù)據(jù)源
	 */
	@Primary
	@Bean(name = "primaryDataSource")
	@ConfigurationProperties(prefix = "spring.datasource.hikari.primary") // 配置
																			// primary
																			// 數(shù)據(jù)源所?的
																			// hikari
																			// 配置
																			// key
																			// 的前綴
	public DataSource dataSource(
			@Qualifier("primaryDataSourceProperties") DataSourceProperties primaryDataSourceProperties) {
		HikariDataSource dataSource = primaryDataSourceProperties.initializeDataSourceBuilder()
				.type(HikariDataSource.class).build();
		if (StringUtils.hasText(primaryDataSourceProperties.getName())) {
			dataSource.setPoolName(primaryDataSourceProperties.getName());
		}
		return dataSource;
	}

	/**
	 * 配置 primary 數(shù)據(jù)源的 entityManagerFactory 命名為
	 * primaryEntityManagerFactory,?來對實體進??些操作
	 *
	 * @param builder
	 *            構(gòu)建器
	 * @param primaryDataSource
	 *            primary 數(shù)據(jù)源
	 * @return primary 實體管理工廠
	 */
	@Primary
	@Bean(name = "primaryEntityManagerFactory")
	public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
			@Qualifier("primaryDataSource") DataSource primaryDataSource) {
		final HashMap<String, Object> hibernateProperties = new HashMap<String, Object>();
		hibernateProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
		return builder.dataSource(primaryDataSource).properties(hibernateProperties)
				// primary 數(shù)據(jù)的實體所在的路徑
				.packages("org.test.data.entity.primary")
				// persistenceUnit 的名字采? primary
				.persistenceUnit("primary").build();
	}

	/**
	 * 配置 primary 數(shù)據(jù)源的事務(wù)管理者,命名為 primaryTransactionManager 依賴
	 * primaryEntityManagerFactory
	 *
	 * @param primaryEntityManagerFactory
	 *            primary 實體管理工廠
	 * @return primary 事務(wù)管理者
	 */
	@Primary
	@Bean(name = "primaryTransactionManager")
	public PlatformTransactionManager transactionManager(
			@Qualifier("primaryEntityManagerFactory") EntityManagerFactory primaryEntityManagerFactory) {
		return new JpaTransactionManager(primaryEntityManagerFactory);
	}
}

第二數(shù)據(jù)源:

package org.test.property.config;

import java.util.HashMap;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.util.StringUtils;

import com.zaxxer.hikari.HikariDataSource;

@Configuration
@EnableTransactionManagement // 開啟事務(wù)
@EnableJpaRepositories( // 利? EnableJpaRepositories 配置哪些包下?的 Repositories,采?哪個
						// EntityManagerFactory 和哪個 TransactionManagement
		basePackages = { "org.test.dao.second" },
		entityManagerFactoryRef = "secondEntityManagerFactory", 
		transactionManagerRef = "secondTransactionManager" 
)
public class TestSecondDataSourceConfig {

	/**
	 * 指定 second 數(shù)據(jù)源的 dataSource 配置
	 *
	 * @return second 數(shù)據(jù)源配置
	 */
	@Bean(name = "secondDataSourceProperties")
	// @Qualifier(value = "secondDataSourceProperties")
	@ConfigurationProperties("spring.datasource.second") // second 數(shù)據(jù)源的配置前綴采?
														// spring.datasource.second
	public DataSourceProperties secondDataSourceProperties() {
		return new DataSourceProperties();
	}

	/**
	 * 可以選擇不同的數(shù)據(jù)源,這?使? HikariDataSource,創(chuàng)建數(shù)據(jù)源
	 *
	 * @param secondDataSourceProperties
	 *            數(shù)據(jù)源配置
	 * @return second 數(shù)據(jù)源
	 */
	@Bean(name = "secondDataSource")
	// @Qualifier(value = "secondDataSource")
	@ConfigurationProperties(prefix = "spring.datasource.hikari.second") // 配置
																		// second
																		// 數(shù)據(jù)源所?的
																		// hikari
																		// 配置
																		// key
																		// 的前綴
	public DataSource dataSource() {
		DataSourceProperties secondDataSourceProperties = secondDataSourceProperties();
		HikariDataSource dataSource = secondDataSourceProperties.initializeDataSourceBuilder()
				.type(HikariDataSource.class).build();
		if (StringUtils.hasText(secondDataSourceProperties.getName())) {
			dataSource.setPoolName(secondDataSourceProperties.getName());
		}
		return dataSource;
	}

	/**
	 * 配置 second 數(shù)據(jù)源的 entityManagerFactory 命名為
	 * secondEntityManagerFactory,?來對實體進??些操作
	 *
	 * @param builder
	 *            構(gòu)建器
	 * @param secondDataSource
	 *            second 數(shù)據(jù)源
	 * @return second 實體管理工廠
	 */
	@Bean(name = "secondEntityManagerFactory")
	// @Qualifier(value = "secondEntityManagerFactory")
	public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) {
		final HashMap<String, Object> hibernateProperties = new HashMap<String, Object>();
		hibernateProperties.put("hibernate.dialect", "org.hibernate.dialect.DmDialect");
		return builder.dataSource(dataSource()).properties(hibernateProperties)
				// second 數(shù)據(jù)的實體所在的路徑
				.packages("org.test.data.entity.second")
				// persistenceUnit 的名字采? second
				.persistenceUnit("second").build();
	}

	/**
	 * 配置 second 數(shù)據(jù)源的事務(wù)管理者,命名為 secondTransactionManager 依賴
	 * secondEntityManagerFactory
	 *
	 * @param secondEntityManagerFactory
	 *            second 實體管理工廠
	 * @return second 事務(wù)管理者
	 */
	@Bean(name = "secondTransactionManager")
	// @Qualifier(value = "")
	public PlatformTransactionManager transactionManager(
			@Qualifier("secondEntityManagerFactory") EntityManagerFactory secondEntityManagerFactory) {
		return new JpaTransactionManager(secondEntityManagerFactory);
	}
}

配置文件部分(application.properties)

如需更為yml,可自行轉(zhuǎn)換。
其中數(shù)據(jù)庫連接池為觀察效果用,可根據(jù)實際自行配置

#############################################
#######jpa setting
#############################################
#JPA Configuration:  
# Show or not log for each sql query
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto=update
#spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect  
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy

# 主數(shù)據(jù)源配置
spring.datasource.primary.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.primary.url=
spring.datasource.primary.username=
spring.datasource.primary.password=
# 主數(shù)據(jù)源連接池配置(主要為觀察多數(shù)據(jù)源配置效果,可按實際配置或不配置)
# spring.datasource.hikari.primary.pool-name=jpa-hikari-pool-primary
# spring.datasource.hikari.primary.max-lifetime=900000
# spring.datasource.hikari.primary.maximum-pool-size=8

spring.datasource.second.driver-class-name=dm.jdbc.driver.DmDriver
spring.datasource.second.url=
spring.datasource.second.username=
spring.datasource.second.password=
# 第二數(shù)據(jù)源連接池配置(主要為觀察多數(shù)據(jù)源配置效果,可按實際配置或不配置)
# spring.datasource.hikari.second.pool-name=jpa-hikari-pool-second
# spring.datasource.hikari.second.max-lifetime=500000
# spring.datasource.hikari.second.maximum-pool-size=6

Controller部分(測試)

此為測試效果用,不推薦直接在controller層調(diào)用dao層寫法。

package org.test.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.test.data.entity.primary.Test;
import org.test.service.TestService;

@RestController
@RequestMapping("/test")
public class TestController {
	@Autowired
	private TestRepository testRepository;
	@Autowired
	private TestRepository2 testRepository2;
	
	@GetMapping
	public String test(String name) {
		testRepository.save(new Test(null, name));
		testRepository2.save(new Test2(null, name));
		return "ok";
	}
}

至此,便完成全部配置!

可能碰見的問題

1. 報語法不匹配/不支持問題“org.hibernate.HibernateException:對DialectResolutionInfo的訪問在’hibernate.dialect’未設(shè)置時不能為空”

EntityManager工廠配置LocalContainerEntityManagerFactoryBean中添加方言指定:

hibernateProperties.put("hibernate.dialect", "org.hibernate.dialect.DmDialect");

詳情可查看**配置部分(Configuration)**中TestSecondDataSourceConfig相關(guān)代碼。

參考文章:使用多個數(shù)據(jù)源時,Spring boot Hibernate錯誤“當“Hibernate.dialent”未設(shè)置時,對方言解析信息的訪問不能為null” - 一點教程

2. 報“僅當指定列列表,且SET IDENTITY_INSERT為ON時,才能對自增列賦值”問題

  1. 在版本8.1.1.49中,可通過將主鍵字段序列設(shè)置為@GeneratedValue(strategy = GenerationType.AUTO)解決
  2. 在版本8.1.2.192中,該問題已被解決。注意,新版本驅(qū)動更改了artifactId,詳情如下:
    舊:
<dependency>
	<groupId>com.dameng</groupId>
	<artifactId>Dm8JdbcDriver18</artifactId>
	<version>8.1.1.49</version>
</dependency>

<dependency>
	<groupId>com.dameng</groupId>
	<artifactId>DmDialect-for-hibernate5.3</artifactId>
	<version>8.1.1.49</version>
</dependency>

新:

<dependency>
	<groupId>com.dameng</groupId>
	<artifactId>DmJdbcDriver18</artifactId>
	<version>8.1.2.192</version>
</dependency>

<dependency>
	<groupId>com.dameng</groupId>
	<artifactId>DmDialect-for-hibernate5.3</artifactId>
	<version>8.1.2.192</version>
</dependency>

3. 啟動時報“org.hibernate.engine.jdbc.spi.TypeInfo : HHH000362: Unable to retrieve type info result set : dm.jdbc.driver.DMException: 第 1 行, 第 270 列[AUTO_INCREMENT]附近出現(xiàn)錯誤”問題

解決方法如問題2解決方法2即可。

參考文章

Spring Data JPA 之 多數(shù)據(jù)源配置_jpa 多數(shù)據(jù)源_曾小二的禿頭之路的博客-CSDN博客
使用多個數(shù)據(jù)源時,Spring boot Hibernate錯誤“當“Hibernate.dialent”未設(shè)置時,對方言解析信息的訪問不能為null” - 一點教程
spring boot mysql8 遷移到達夢報錯[AUTO_INCREMENT]附近出現(xiàn)錯誤_wdd668的博客-CSDN博客
dm.jdbc.driver.DMException: 第 1 行, 第 270 列[AUTO_INCREMENT]附近出現(xiàn)錯誤:語法分析出錯 | 達夢技術(shù)社區(qū)文章來源地址http://www.zghlxwxcb.cn/news/detail-753065.html

到了這里,關(guān)于spring boot下基于spring data jpa配置mysql+達夢多數(shù)據(jù)源(以不同包路徑方式,mysql為主數(shù)據(jù)源)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • Jpa與Druid線程池及Spring Boot整合(一): spring-boot-starter-data-jpa 搭建持久層

    Jpa與Druid線程池及Spring Boot整合(一): spring-boot-starter-data-jpa 搭建持久層

    ? ? ? ? ? ? ? ? ? ? ? Jpa與Druid線程池及Spring Boot整合(一) Jpa與Druid線程池及Spring Boot整合(二):幾個坑 附錄官網(wǎng)文檔:core.domain-events域事件 docker實戰(zhàn)(一):centos7 yum安裝docker docker實戰(zhàn)(二):基礎(chǔ)命令篇 docker實戰(zhàn)(三):docker網(wǎng)絡(luò)模式(超詳細) docker實戰(zhàn)(四):docker架構(gòu)原理 docker實戰(zhàn)(五

    2024年02月13日
    瀏覽(34)
  • Spring Boot 篇四: Spring Data JPA使用SQL Server

    Spring Boot 篇四: Spring Data JPA使用SQL Server

    本篇介紹篇一至篇三中用到的JPA鏈接SQL Server的具體情況以及實戰(zhàn)過程中可能遇到的問題。 具體的下載和安裝教程,請參閱微軟SQL Server官網(wǎng); SQL Server Express 是免費的,并且配套的SQL Server Management Studio也是可以用的。 呃,當然,使用Docker來運行SQL Server是另外一條路徑。具體

    2024年02月05日
    瀏覽(17)
  • Jpa與Druid線程池及Spring Boot整合(二): spring-boot-starter-data-jpa 踏坑異常處理方案

    Jpa與Druid線程池及Spring Boot整合(二): spring-boot-starter-data-jpa 踏坑異常處理方案

    ? ? ? ? ? ? ? ? ? ?? docker實戰(zhàn)(一):centos7 yum安裝docker docker實戰(zhàn)(二):基礎(chǔ)命令篇 docker實戰(zhàn)(三):docker網(wǎng)絡(luò)模式(超詳細) docker實戰(zhàn)(四):docker架構(gòu)原理 docker實戰(zhàn)(五):docker鏡像及倉庫配置 docker實戰(zhàn)(六):docker 網(wǎng)絡(luò)及數(shù)據(jù)卷設(shè)置 docker實戰(zhàn)(七):docker 性質(zhì)及版本選擇 認知升維: 道、法、

    2024年02月13日
    瀏覽(27)
  • 【Spring Boot】SpringBoot和數(shù)據(jù)庫交互: 使用Spring Data JPA

    在現(xiàn)代應(yīng)用程序的開發(fā)中,數(shù)據(jù)是核心部分。為了能夠持久化、檢索、更新和刪除數(shù)據(jù),應(yīng)用程序需要與數(shù)據(jù)庫進行交互。 1.1 為什么需要數(shù)據(jù)庫交互 數(shù)據(jù)持久化 :當你關(guān)閉應(yīng)用程序或者服務(wù)器時,你仍希望數(shù)據(jù)能夠保存。數(shù)據(jù)庫提供了一個持久的存儲方案,使得數(shù)據(jù)在關(guān)閉

    2024年02月12日
    瀏覽(28)
  • 如何使用Spring Data JPA簡化MySQL數(shù)據(jù)訪問

    本篇文章是 “一起學(xué)習mysql” 系列的第五篇文章,本篇文章我們學(xué)習一下Spring Data JPA的使用,在開始學(xué)習器,我們先來了解一下什么是JPA。 JPA的全稱是Java Persistence API,是J2EE中的一條規(guī)范,它標準化了數(shù)據(jù)持久化API。在上一篇文章中,我們了解了如何使用MyBatis進行MySQL數(shù)據(jù)

    2024年02月15日
    瀏覽(27)
  • Spring Boot 配置雙數(shù)據(jù)源

    Spring Boot 配置雙數(shù)據(jù)源

    Survive by day and develop by night. talk for import biz , show your perfect code,full busy,skip hardness,make a better result,wait for change,challenge Survive. happy for hardess to solve denpendies. 需求: 1.基本步驟 添加依賴 添加 Spring Boot 和數(shù)據(jù)庫驅(qū)動的依賴 配置數(shù)據(jù)源 在 application.properties 或 application.yml 中分別配

    2024年01月22日
    瀏覽(23)
  • 【Java】Spring Boot配置動態(tài)數(shù)據(jù)源

    1.1 創(chuàng)建動態(tài)數(shù)據(jù)源 通過實現(xiàn)Spring提供的AbstractRoutingDataSource類,可以實現(xiàn)自己的數(shù)據(jù)源選擇邏輯,從而可以實現(xiàn)數(shù)據(jù)源的動態(tài)切換。 1.2 創(chuàng)建動態(tài)數(shù)據(jù)源配置類 跟配置靜態(tài)多數(shù)據(jù)源一樣,需要手動配置下面的三個 Bean,只不過DynamicDataSource類的targetDataSources是空的。 1.3 創(chuàng)建動

    2024年02月09日
    瀏覽(25)
  • Spring Boot配置多個Kafka數(shù)據(jù)源

    application.properties配置文件如下 1.第一個kakfa 2.第二個kakfa 備注: 生產(chǎn)者消費者代碼參考鏈接,開發(fā)同學(xué)需要以實際情況按要求自己變更下代碼即可: Spring Boot 集成多個 Kafka_springboot集成多個kafka_//承續(xù)緣_紀錄片的博客-CSDN博客

    2024年02月07日
    瀏覽(27)
  • Spring Boot整合Mybatis配置多數(shù)據(jù)源

    在之前的事件管理系統(tǒng)博客中有提到動態(tài)的多數(shù)據(jù)源配置 工作中難免需要做幾個工具方便自己偷懶,加上之前的擋板,數(shù)據(jù)源肯定沒法單一配置,所以需要多數(shù)據(jù)源配置。這里介紹兩種配置:動態(tài)數(shù)據(jù)源和固定數(shù)據(jù)源模式。這兩種我在目前的工作的工具開發(fā)中都有用到。 M

    2024年01月23日
    瀏覽(29)
  • 如何在Spring Boot中配置雙數(shù)據(jù)源?

    在許多應(yīng)用程序中, 可能會遇到需要連接多個數(shù)據(jù)庫的情況 。這些數(shù)據(jù)庫可以是不同的類型,例如關(guān)系型數(shù)據(jù)庫和NoSQL數(shù)據(jù)庫,或者它們可以是相同類型但包含不同的數(shù)據(jù)。為了處理這種情況,我們可以使用雙數(shù)據(jù)源來管理多個數(shù)據(jù)庫連接。 雙數(shù)據(jù)源是指在一個應(yīng)用程序中

    2024年02月11日
    瀏覽(20)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包