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); } }