其pom文件如下
2.application.yml4.0.0 org.springframework.boot spring-boot-starter-parent2.3.2.RELEASE com.atguigu.gulimall gulimall-search0.0.1-SNAPSHOT gulimall-search ES检索服务 1.8 7.4.2 org.springframework.boot spring-boot-starter-webcom.atguigu.gulimall gulimall-common0.0.1-SNAPSHOT org.elasticsearch.client elasticsearch-rest-high-level-client7.4.2 org.springframework.boot spring-boot-starter-testtest org.springframework.boot spring-boot-maven-plugin
配置nacos注册中心地址
server: port: 12000 spring: application: name: gulimall-search cloud: nacos: discovery: server-addr: localhost:8848 logging: level: com.atguigu.gulimall.search: debug3.启动类
排除数据源
package com.atguigu.gulimall.gulimallsearch; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @EnableDiscoveryClient @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class GulimallSearchApplication { public static void main(String[] args) { SpringApplication.run(GulimallSearchApplication.class, args); } }4.ES配置类
新建config包
package com.atguigu.gulimall.gulimallsearch.config; import org.apache.http.HttpHost; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.client.RestHighLevelClient; import org.springframework.boot.SpringBootConfiguration; import org.springframework.context.annotation.Bean; @SpringBootConfiguration public class GulimallESConfiguration { @Bean RestHighLevelClient client() { RestClientBuilder builder = RestClient.builder( new HttpHost("192.168.56.10", 9200, "http")); return new RestHighLevelClient(builder); } }5.测试类
package com.atguigu.gulimall.gulimallsearch; import org.elasticsearch.client.RestHighLevelClient; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class GulimallSearchApplicationTests { @Autowired private RestHighLevelClient restHighLevelClient; @Test void contextLoads() { System.out.println(restHighLevelClient); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)