【spring boot】【elasticsearch】spring boot整合elasticsearch,啟動報錯Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], reje
阿新 • • 發佈:2019-01-03
spring boot整合elasticsearch,
啟動報錯:
Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8] at io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:51) ~[netty-common-4.1.23.Final.jar:4.1.23.Final] at io.netty.util.NettyRuntime.setAvailableProcessors(NettyRuntime.java:87) ~[netty-common-4.1.23.Final.jar:4.1.23.Final] at org.elasticsearch.transport.netty4.Netty4Utils.setAvailableProcessors(Netty4Utils.java:85) ~[transport-netty4-client-5.6.8.jar:5.6.8] at org.elasticsearch.transport.netty4.Netty4Transport.<init>(Netty4Transport.java:140) ~[transport-netty4-client-5.6.8.jar:5.6.8] at org.elasticsearch.transport.Netty4Plugin.lambda$getTransports$0(Netty4Plugin.java:93) ~[transport-netty4-client-5.6.8.jar:5.6.8] at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:177) ~[elasticsearch-5.6.8.jar:5.6.8] at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:268) ~[elasticsearch-5.6.8.jar:5.6.8] at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:133) ~[transport-5.6.8.jar:5.6.8] at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:119) ~[transport-5.6.8.jar:5.6.8] at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:109) ~[transport-5.6.8.jar:5.6.8] at org.springframework.data.elasticsearch.client.TransportClientFactoryBean.buildClient(TransportClientFactoryBean.java:91) ~[spring-data-elasticsearch-3.0.6.RELEASE.jar:3.0.6.RELEASE] at org.springframework.data.elasticsearch.client.TransportClientFactoryBean.afterPropertiesSet(TransportClientFactoryBean.java:86) ~[spring-data-elasticsearch-3.0.6.RELEASE.jar:3.0.6.RELEASE] at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration.elasticsearchClient(ElasticsearchAutoConfiguration.java:59) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$13fe0eee.CGLIB$elasticsearchClient$0(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$13fe0eee$$FastClassBySpringCGLIB$$480cb39c.invoke(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE] at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$13fe0eee.elasticsearchClient(<generated>) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_171] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE] ... 24 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); } }