Spring Boot ElasticSearch 整合异常汇总
ElasticSearch地址没有配置
- 异常描述
|
1
2 |
Cannot resolve reference to bean 'elasticsearchTemplate' while setting bean property 'elasticsearchOperations';
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'elasticsearchTemplate' available |
- 解决方案
application.properties(yml)增加配置
|
1
|
spring.data.elasticsearch.cluster-nodes=192.168.130.59:9300
|
多模块使用Netty冲突
- 异常描述
|
1
2 |
Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method 'elasticsearchClient' threw exception;
nested exception is java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4] |
- 解决方案
两个地方增加配置参数
Spring Boot 启动类增加配置参数,增加后启动服务不报错。
|
1
2 3 4 5 6 7 8 9 |
package tech.zhuyuan.demo;
@SpringBootApplication @EnableDiscoveryClient public class Bootstrap { public static void main(String[] args) { System.setProperty("es.set.netty.runtime.available.processors", "false"); UniosApplication.run("Bootstrap", Bootstrap.class, args); } } |
ES配置增加配置参数,增加后单元测试不报错。
|
1
2 3 4 5 6 7 8 9 10 11 |
@Configuration
public class ElasticSearchConfig { /** * 防止netty的bug * java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4] */ @PostConstruct void init() { System.setProperty("es.set.netty.runtime.available.processors", "false"); } } |
浙公网安备 33010602011771号