ElasticSearch地址没有配置
- 异常描述
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)增加配置
spring.data.elasticsearch.cluster-nodes=192.168.130.59:9300
多模块使用Netty冲突
- 异常描述
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 启动类增加配置参数,增加后启动服务不报错。
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配置增加配置参数,增加后单元测试不报错。
@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");
}
}