多数据源和es版本问题

多数据源
spring:
application:
name: integration-datasync
datasource:
dynamic:
primary: base
datasource:
base:
url: jdbc:mysql://192.168.31.234:3306/security_db?characterEncoding=utf8&useTimezone=true&serverTimezone=GMT%2B8&useSSL=false
username: root
password:
driverClassName: com.mysql.cj.jdbc.Driver
source:
url: jdbc:mysql://192.168.31.234:3306/security_db_sync?characterEncoding=utf8&useTimezone=true&serverTimezone=GMT%2B8&useSSL=false
username: root
password: !
driver-class-name: com.mysql.cj.jdbc.Driver

com.baomidou dynamic-datasource-spring-boot-starter 2.5.6

@DS(“source”) aop原理
同层调用会失败 事务 ds asyc!!!

SpringBoot2.2.x版本才支持ElasticSearch7.x,需要先升级SpringBoot版本
6.0ElasticsearchTemplate 替换为 7.0ElasticsearchRestTemplate(TransportClient 替换为 RestHighLevelClient ) 很多方法不一样!!! config配置yml配置
SpringBoot2.2.x版本才支持ElasticSearch7.x es7的java代码,只能使用restclient,TransportClient被废弃
是由于6.0的版本不允许一个index下面有多个type,并且官方说是在接下来的7.0版本中会删掉type

org.springframework.data spring-data-elasticsearch x.y.z.RELEASE org.elasticsearch.client transport x.y.z
es的版本
org.elasticsearch elasticsearch 6.2.3

这里使用了ElasticsearchRestTemplate这个类,对应于RestHighLevelClient

public class EsConfiguration extends AbstractElasticsearchConfiguration {
@Override
@Bean
public RestHighLevelClient elasticsearchClient() {
final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo(“localhost:9200”)
.build();

    return RestClients.create(clientConfiguration).rest();
}

@Bean
public ElasticsearchRestTemplate elasticsearchRestTemplate(){
    return new ElasticsearchRestTemplate(elasticsearchClient());
}

@Configuration
public class TransportClientConfig extends ElasticsearchConfigurationSupport {

@Bean
public Client elasticsearchClient() throws UnknownHostException {
	Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
	TransportClient client = new PreBuiltTransportClient(settings);
            // 注意端口为 9300
	client.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
	return client;
}

@Bean(name = {"elasticsearchOperations", "elasticsearchTemplate"})
public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
	return new ElasticsearchTemplate(elasticsearchClient(), entityMapper());
}

}

@Bean
public TransportClient transportClient() throws UnknownHostException {
TransportClient client = new PreBuiltXPackTransportClient(Settings.builder()
.put(“cluster.name”, “es-cluster”)
.put(“xpack.security.user”, “elastic:changeme”)
.build())
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(“127.0.0.1”), 9300));
return client;
}

spring:
elasticsearch:
#es配置
rest:
#最新配置方式使用restful风格,端口从9300 -> 9200
uris: xx.xx.xx.xx:9200
username: elastic
password: xxx

data:
elasticsearch:
cluster-name: data-lakes
cluster-nodes: 192.168.31.30:9300,192.168.31.31:9300
#cluster-password: elastic:xxx

你可能感兴趣的:(项目,elasticsearch)