问题
SpringBoot-2.* 在整合 elasticsearch-7.3.0 会报如下错误
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
2019-08-15 21:10:27.770 INFO 14616 --- [ restartedMain] com.xu.springboot.Application : Starting Application on DESKTOP-S8ILBFP with PID 14616 (F:\SourceCode\Eclipse-2019-03\SpringBoot_Learn\target\classes started by hyacinth in F:\SourceCode\Eclipse-2019-03\SpringBoot_Learn)
2019-08-15 21:10:27.772 INFO 14616 --- [ restartedMain] com.xu.springboot.Application : The following profiles are active: dev
2019-08-15 21:10:27.826 INFO 14616 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-08-15 21:10:27.826 INFO 14616 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-08-15 21:10:28.676 INFO 14616 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2019-08-15 21:10:28.678 INFO 14616 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-08-15 21:10:28.746 INFO 14616 --- [ restartedMain] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.xu.springboot.repository.ArticleRepository.
2019-08-15 21:10:28.746 INFO 14616 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 56ms. Found 0 repository interfaces.
2019-08-15 21:10:29.154 INFO 14616 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$7f84326d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-15 21:10:29.568 INFO 14616 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-08-15 21:10:29.583 INFO 14616 --- [ restartedMain] o.a.coyote.http11.Http11NioProtocol : Initializing ProtocolHandler ["http-nio-8080"]
2019-08-15 21:10:29.594 INFO 14616 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-15 21:10:29.594 INFO 14616 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-08-15 21:10:29.758 INFO 14616 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-15 21:10:29.759 INFO 14616 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1933 ms
init filter
mybatis-plus init success.
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
2019-08-15 21:10:30.336 ERROR 14616 --- [ restartedMain] c.a.druid.pool.DruidAbstractDataSource : maxIdle is deprecated
Using VFS adapter com.baomidou.mybatisplus.spring.boot.starter.SpringBootVFS
Checking to see if class com.xu.springboot.entity.Student matches criteria [is assignable to Object]
Checking to see if class com.xu.springboot.entity.Style matches criteria [is assignable to Object]
Checking to see if class com.xu.springboot.entity.Test matches criteria [is assignable to Object]
Checking to see if class com.xu.springboot.entity.User matches criteria [is assignable to Object]
Scanned package: 'com.xu.springboot.entity' for aliases
Registered plugin: 'com.baomidou.mybatisplus.plugins.PaginationInterceptor@1998af73'
2019-08-15 21:10:31.077 INFO 14616 --- [ restartedMain] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
{com.xu.springboot.mapper.StudentMapper.deleteById} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.
{com.xu.springboot.mapper.StudentMapper.updateById} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.
{com.xu.springboot.mapper.StudentMapper.selectById} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.
{com.xu.springboot.mapper.StudentMapper.insert} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.
Parsed mapper file: 'file [F:\SourceCode\Eclipse-2019-03\SpringBoot_Learn\target\classes\mapper\StudentMapper.xml]'
2019-08-15 21:10:31.636 INFO 14616 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-15 21:10:31.830 WARN 14616 --- [ restartedMain] org.thymeleaf.templatemode.TemplateMode : [THYMELEAF][restartedMain] Template Mode 'HTML5' is deprecated. Using Template Mode 'HTML' instead.
2019-08-15 21:10:32.272 INFO 14616 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : no modules loaded
2019-08-15 21:10:32.273 INFO 14616 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
2019-08-15 21:10:32.274 INFO 14616 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2019-08-15 21:10:32.274 INFO 14616 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2019-08-15 21:10:32.274 INFO 14616 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
2019-08-15 21:10:32.274 INFO 14616 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019-08-15 21:10:33.632 WARN 14616 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchClient' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.IllegalStateException: availableProcessors is already set to [16], rejecting [16]
2019-08-15 21:10:33.633 INFO 14616 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
2019-08-15 21:10:33.638 INFO 14616 --- [ restartedMain] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} closed
2019-08-15 21:10:33.679 INFO 14616 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
destroy filter
2019-08-15 21:10:33.689 INFO 14616 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-08-15 21:10:33.692 ERROR 14616 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticsearchClient' defined in class path resource [org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.IllegalStateException: availableProcessors is already set to [16], rejecting [16]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202)
at com.xu.springboot.Application.main(Application.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.transport.TransportClient]: Factory method 'elasticsearchClient' threw exception; nested exception is java.lang.IllegalStateException: availableProcessors is already set to [16], rejecting [16]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
... 24 common frames omitted
Caused by: java.lang.IllegalStateException: availableProcessors is already set to [16], rejecting [16]
at io.netty.util.NettyRuntime$AvailableProcessorsHolder.setAvailableProcessors(NettyRuntime.java:51)
at io.netty.util.NettyRuntime.setAvailableProcessors(NettyRuntime.java:87)
at org.elasticsearch.transport.netty4.Netty4Utils.setAvailableProcessors(Netty4Utils.java:83)
at org.elasticsearch.transport.netty4.Netty4Transport.<init>(Netty4Transport.java:112)
at org.elasticsearch.transport.Netty4Plugin.lambda$getTransports$0(Netty4Plugin.java:86)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:189)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:283)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:128)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:114)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:104)
at org.springframework.data.elasticsearch.client.TransportClientFactoryBean.buildClient(TransportClientFactoryBean.java:85)
at org.springframework.data.elasticsearch.client.TransportClientFactoryBean.afterPropertiesSet(TransportClientFactoryBean.java:80)
at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration.elasticsearchClient(ElasticsearchAutoConfiguration.java:59)
at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$4a6d53a5.CGLIB$elasticsearchClient$0(<generated>)
at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$4a6d53a5$$FastClassBySpringCGLIB$$af19b413.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$4a6d53a5.elasticsearchClient(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 25 common frames omitted
解决
首先在pom.xml 文件中添加 elasticsearch 客户端依赖
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
</dependency>
然后在SpringBoot启动类中添加 System.setProperty(“es.set.netty.runtime.available.processors”, “false”); 项目就能启动成功
package com.xu.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
System.setProperty("es.set.netty.runtime.available.processors", "false");
SpringApplication.run(Application.class, args);
}
}
结果
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
2019-08-15 21:07:34.161 INFO 7536 --- [ restartedMain] com.xu.springboot.Application : Starting Application on DESKTOP-S8ILBFP with PID 7536 (F:\SourceCode\Eclipse-2019-03\SpringBoot_Learn\target\classes started by hyacinth in F:\SourceCode\Eclipse-2019-03\SpringBoot_Learn)
2019-08-15 21:07:34.163 INFO 7536 --- [ restartedMain] com.xu.springboot.Application : The following profiles are active: dev
2019-08-15 21:07:34.212 INFO 7536 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-08-15 21:07:34.212 INFO 7536 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-08-15 21:07:35.045 INFO 7536 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2019-08-15 21:07:35.048 INFO 7536 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-08-15 21:07:35.114 INFO 7536 --- [ restartedMain] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.xu.springboot.repository.ArticleRepository.
2019-08-15 21:07:35.114 INFO 7536 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 55ms. Found 0 repository interfaces.
2019-08-15 21:07:35.504 INFO 7536 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$51d3ce0b] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-15 21:07:36.152 INFO 7536 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-08-15 21:07:36.167 INFO 7536 --- [ restartedMain] o.a.coyote.http11.Http11NioProtocol : Initializing ProtocolHandler ["http-nio-8080"]
2019-08-15 21:07:36.179 INFO 7536 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-15 21:07:36.179 INFO 7536 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-08-15 21:07:36.345 INFO 7536 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-15 21:07:36.345 INFO 7536 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2133 ms
init filter
mybatis-plus init success.
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
2019-08-15 21:07:36.910 ERROR 7536 --- [ restartedMain] c.a.druid.pool.DruidAbstractDataSource : maxIdle is deprecated
Using VFS adapter com.baomidou.mybatisplus.spring.boot.starter.SpringBootVFS
Checking to see if class com.xu.springboot.entity.Student matches criteria [is assignable to Object]
Checking to see if class com.xu.springboot.entity.Style matches criteria [is assignable to Object]
Checking to see if class com.xu.springboot.entity.Test matches criteria [is assignable to Object]
Checking to see if class com.xu.springboot.entity.User matches criteria [is assignable to Object]
Scanned package: 'com.xu.springboot.entity' for aliases
Registered plugin: 'com.baomidou.mybatisplus.plugins.PaginationInterceptor@4098243c'
2019-08-15 21:07:37.673 INFO 7536 --- [ restartedMain] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
{com.xu.springboot.mapper.StudentMapper.deleteById} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.
{com.xu.springboot.mapper.StudentMapper.updateById} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.
{com.xu.springboot.mapper.StudentMapper.selectById} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.
{com.xu.springboot.mapper.StudentMapper.insert} Has been loaded by XML or SqlProvider, ignoring the injection of the SQL.
Parsed mapper file: 'file [F:\SourceCode\Eclipse-2019-03\SpringBoot_Learn\target\classes\mapper\StudentMapper.xml]'
2019-08-15 21:07:38.225 INFO 7536 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-15 21:07:38.405 WARN 7536 --- [ restartedMain] org.thymeleaf.templatemode.TemplateMode : [THYMELEAF][restartedMain] Template Mode 'HTML5' is deprecated. Using Template Mode 'HTML' instead.
2019-08-15 21:07:38.838 INFO 7536 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : no modules loaded
2019-08-15 21:07:38.839 INFO 7536 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
2019-08-15 21:07:38.840 INFO 7536 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2019-08-15 21:07:38.840 INFO 7536 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2019-08-15 21:07:38.840 INFO 7536 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
2019-08-15 21:07:38.840 INFO 7536 --- [ restartedMain] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019-08-15 21:07:40.395 INFO 7536 --- [ restartedMain] o.s.d.e.c.TransportClientFactoryBean : Adding transport node : 127.0.0.1:9300
2019-08-15 21:07:43.181 INFO 7536 --- [ restartedMain] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2019-08-15 21:07:43.631 INFO 7536 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2019-08-15 21:07:43.658 INFO 7536 --- [ restartedMain] o.a.coyote.http11.Http11NioProtocol : Starting ProtocolHandler ["http-nio-8080"]
2019-08-15 21:07:43.679 INFO 7536 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-08-15 21:07:43.681 INFO 7536 --- [ restartedMain] com.xu.springboot.Application : Started Application in 10.092 seconds (JVM running for 10.711)