【spring boot】【elasticsearch】spring boot整合elasticsearch,启动报错Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8

spring boot整合elasticsearch,

启动报错:

Caused by: java.lang.IllegalStateException: availableProcessors is already set to [], rejecting []
at io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:) ~[netty-common-4.1..Final.jar:4.1..Final]
at io.netty.util.NettyRuntime.setAvailableProcessors(NettyRuntime.java:) ~[netty-common-4.1..Final.jar:4.1..Final]
at org.elasticsearch.transport.netty4.Netty4Utils.setAvailableProcessors(Netty4Utils.java:) ~[transport-netty4-client-5.6..jar:5.6.]
at org.elasticsearch.transport.netty4.Netty4Transport.<init>(Netty4Transport.java:) ~[transport-netty4-client-5.6..jar:5.6.]
at org.elasticsearch.transport.Netty4Plugin.lambda$getTransports$(Netty4Plugin.java:) ~[transport-netty4-client-5.6..jar:5.6.]
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:) ~[elasticsearch-5.6..jar:5.6.]
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:) ~[elasticsearch-5.6..jar:5.6.]
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:) ~[transport-5.6..jar:5.6.]
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:) ~[transport-5.6..jar:5.6.]
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:) ~[transport-5.6..jar:5.6.]
at org.springframework.data.elasticsearch.client.TransportClientFactoryBean.buildClient(TransportClientFactoryBean.java:) ~[spring-data-elasticsearch-3.0..RELEASE.jar:3.0..RELEASE]
at org.springframework.data.elasticsearch.client.TransportClientFactoryBean.afterPropertiesSet(TransportClientFactoryBean.java:) ~[spring-data-elasticsearch-3.0..RELEASE.jar:3.0..RELEASE]
at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration.elasticsearchClient(ElasticsearchAutoConfiguration.java:) ~[spring-boot-autoconfigure-2.0..RELEASE.jar:2.0..RELEASE]
at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$13fe0eee.CGLIB$elasticsearchClient$(<generated>) ~[spring-boot-autoconfigure-2.0..RELEASE.jar:2.0..RELEASE]
at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$13fe0eee$$FastClassBySpringCGLIB$$480cb39c.invoke(<generated>) ~[spring-boot-autoconfigure-2.0..RELEASE.jar:2.0..RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:) ~[spring-core-5.0..RELEASE.jar:5.0..RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:) ~[spring-context-5.0..RELEASE.jar:5.0..RELEASE]
at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$13fe0eee.elasticsearchClient(<generated>) ~[spring-boot-autoconfigure-2.0..RELEASE.jar:2.0..RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:) ~[na:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:) ~[na:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:) ~[na:1.8.0_171]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:) ~[spring-beans-5.0..RELEASE.jar:5.0..RELEASE]
... common frames omitted

解决方案:

在启动类添加

@EnableScheduling
@SpringBootApplication
@MapperScan("com.sxd.swapping.dao.mybatis")
public class SwappingApplication { public static void main(String[] args) {
/**
* Springboot整合Elasticsearch 在项目启动前设置一下的属性,防止报错
* 解决netty冲突后初始化client时还会抛出异常
* java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4]
*/
System.setProperty("es.set.netty.runtime.available.processors", "false"
);
SpringApplication.run(SwappingApplication.class, args);
}
}
上一篇:MVC 动态菜单


下一篇:太一星晨:负载均衡啃不动的骨头交给应用交付