SpringBoot+ElasticSearch7.x+JPA配置多数据源
SpringBoot+ElasticSearch7.x+JPA配置多数据源
这里分为测试环境配置和正式环境配置,大体相差无几
ESTestConfig
1 @Configuration2 @ConfigurationProperties(prefix = "es-config")3 @EnableElasticsearchRepositories(basePackages = {"com.tingyu.cdssdatatest.modules.test.*.esrepository"},elasticsearchTemplateRef = "testTemplate")4 public class ESTestConfig extends AbstractElasticsearchConfiguration {5 6 @Value("${es-config.hostAndPortTest}")7 private String hostAndPortTest;8 9 /**
10 * @description: 测试环境ES
11 */
12 @Bean("elasticsearchClientTest")
13 @Override
14 public RestHighLevelClient elasticsearchClient() {15 ClientConfiguration configuration = ClientConfiguration.builder()
16 .connectedTo(hostAndPortTest).build();
17 return RestClients.create(configuration).rest();
18 }
19
20 @Override
21 @Bean(name = { "testOperations", "testTemplate" })
22 public ElasticsearchOperations elasticsearchOperations(ElasticsearchConverter elasticsearchConverter,
23 @Qualifier("elasticsearchClientTest") RestHighLevelClient elasticsearchClient) {24 return new ElasticsearchRestTemplate(elasticsearchClient, elasticsearchConverter);
25 }
26 }
ESOfficialConfig,这里使用了@Primary注解
1 @Configuration2 @ConfigurationProperties(prefix = "es-config")3 @EnableElasticsearchRepositories(basePackages = {"com.tingyu.cdssdatatest.modules.official.*.esrepository"},elasticsearchTemplateRef="officialTemplate")4 public class ESOfficialConfig extends AbstractElasticsearchConfiguration {5 @Value("${es-config.hostAndPortOfficial}")6 private String hostAndPortOfficial;7 8 /**9 * @description: 正式环境ES
10 */
11 @Bean("elasticsearchClientOfficial")
12 @Primary
13 @Override
14 public RestHighLevelClient elasticsearchClient() {15 ClientConfiguration configuration = ClientConfiguration.builder()
16 .connectedTo(hostAndPortOfficial).build();
17 return RestClients.create(configuration).rest();
18 }
19
20 @Override
21 @Bean(name = { "officialOperations", "officialTemplate" })
22 public ElasticsearchOperations elasticsearchOperations(ElasticsearchConverter elasticsearchConverter,
23 @Qualifier("elasticsearchClientOfficial") RestHighLevelClient elasticsearchClient) {24 return new ElasticsearchRestTemplate(elasticsearchClient, elasticsearchConverter);
25 }
26 }
application.yml
esrepository
1 public interface RawMessageRepository extends ElasticsearchRepository<RawMessageDto, String> {
2
3 }
Dto,使用@Document注解进行实体映射,相当于Mysql的@Table注解
SpringBoot+ElasticSearch7.x+JPA配置多数据源相关推荐
- springboot jpa 配置多数据源
jpa 多数据源配置 多个 mysql 数据库配置 springboot jpa 配置多数据源其实也并不难,只需要在 properties 或者 yml中简单配置并在项目中引入配置即可. 下面以 ym ...
- springboot jpa 配置多数据源报错解决 Consider defining a bean named ‘entityManagerFactory‘
版本 springboot 2.6.x 现象 jpa配置多数据源后启动报错 Consider defining a bean named 'entityManagerFactory' 解决 方法1:将 ...
- Springboot环境下mybatis配置多数据源配置
mybatis多数据源配置(本文示例为两个),方便实现数据库的读写分离,分库分表功能 本文基于springboot2进行的配置,如版本为springboot1系列则需修改yml的配置(在文末附带) m ...
- springboot + JPA 配置双数据源
一.首先配置application.yml文件设置主从数据库 spring:servlet:multipart:max-file-size: 20MBmax-request-size: 20MBpro ...
- springboot+jpa配置多数据源(Oracle+SqlServer)
本贴主要讲解配置多数据源 springboot+jpa的整合需要自行准备好 1.maven中要导入Oracle和SqlServer的jar包 <dependency><groupId ...
- SpringBoot JPA配置多数据源(同类型库)教程
SpringBoot项目配置多数据源主要分为以下个步骤: 确定好所连接的数据库的资源(包括url username password) 将两个库的信息写入到配置文件中(application.yaml ...
- springboot2+JPA 配置多数据源(不同类型数据库)
注意:看此篇文章之前,springboot+jpa的配置环境应搭建好,不会搭可以自行百度.本文章主要讲述配置JPA多数据源. 1.数据源配置文件 application.properties # 数据 ...
- SpringBoot整合Jpa配置多数据源
前言: 最近接手的SpringBoot项目,原项目数据存储在Oracle上,因后期新增功能考虑到数据量等问题,后期新加功能数据存放在Vertica上,项目中数据库这边主要是用Jpa去持久. 环境: S ...
- 六、springboot(三)配置双数据源
1.目录结构 2.jdbc.properties配置 #db hougespring.datasource.houge.jdbc-url=jdbc:oracle:thin:@192.168.0.120 ...
最新文章
- python全栈-Day 2
- 广发银行运维实践分享:Docker适配传统运维那些事
- 【AI2】更新app inventor离线开发环境百度网盘下载链接,安卓app图形化开发环境...
- SpringBoot+MyBatisPlus+Swagger2.7规范开发接口流程(以废料包材入库与出库为例)
- mongo-mapreduce测试(4)——avg
- java 线程 Thread Runnable 实现样例
- string concat_Java String concat()方法与示例
- java中如何直接导入println()
- 有关Intel主板驱动静默安装的一个坑
- 各家船公司之GX介绍
- json标准格式举例_json几个小例子
- python——函数(定义函数、传递实参、返回值、传递列表、传递任意数量的实参、将函数存储在模块中、函数编写指南)
- Go语言的流程结构简单介绍
- pytorch super 的用法
- php通过curl实现bigpipe
- python生成快递取件码_快递,顺丰,python,截图,15Seconds
- UIKeyboard 键盘
- 基于S32K148快速调试TJA1101
- DC-DC上电时电压输出尖峰电压
- 使用jquery.zsign.js实现在线电子签章功能
热门文章
- QQ超市最佳路径寻路算法改进尝试3
- 思科、华为、华三交换机配置端口聚合
- 思科设备端口聚合配置命令
- python脚本中sparksql split |竖杠竖线
- 007 计算机系统知识——计算机可靠性计算
- 港科夜闻|香港科大录取内地生人数疫情期间不跌反升
- 登录用友时显示不能建立跟服务器的连接,用友GRPR9乡财县管管理软件登录时提示“无法与中间层服务器建立连接,请重新设置中间层”的解决办法知识课件(11页)-原创力文档...
- 3.04.08localStorage与sessionStorage
- 协议分析---HTTP协议和DNS协议
- 4700. 何以包邮?