java.lang.ClassNotFoundException: com.sun.jna.Native
Springboot 集成 ElasticSearch的时候,报错如下:
java.lang.ClassNotFoundException: com.sun.jna.Native at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_65] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_65] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_65] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_65] at java.lang.Class.forName0(Native Method) ~[na:1.8.0_65] at java.lang.Class.forName(Class.java:264) ~[na:1.8.0_65] at org.elasticsearch.bootstrap.Natives.<clinit>(Natives.java:45) ~[elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.bootstrap.BootstrapInfo.isMemoryLocked(BootstrapInfo.java:44) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.monitor.process.ProcessProbe.processInfo(ProcessProbe.java:130) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.monitor.process.ProcessService.<init>(ProcessService.java:44) [elasticsearch-2.4.6.jar:2.4.6] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [na:1.8.0_65] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [na:1.8.0_65] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [na:1.8.0_65] at java.lang.reflect.Constructor.newInstance(Constructor.java:422) [na:1.8.0_65] at org.elasticsearch.common.inject.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:50) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.ConstructorInjector.construct(ConstructorInjector.java:86) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:104) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:47) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:886) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:43) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.Scopes$1$1.get(Scopes.java:59) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:46) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.ConstructorInjector.construct(ConstructorInjector.java:85) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:104) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.ConstructorInjector.construct(ConstructorInjector.java:85) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:104) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:47) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:886) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:43) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.Scopes$1$1.get(Scopes.java:59) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:46) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:201) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:193) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:879) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.InjectorBuilder.loadEagerSingletons(InjectorBuilder.java:193) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:175) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:110) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:93) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:70) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.common.inject.ModulesBuilder.createInjector(ModulesBuilder.java:46) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.node.Node.<init>(Node.java:213) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.node.Node.<init>(Node.java:140) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:143) [elasticsearch-2.4.6.jar:2.4.6] at org.elasticsearch.node.NodeBuilder.node(NodeBuilder.java:150) [elasticsearch-2.4.6.jar:2.4.6] at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration.createNodeClient(ElasticsearchAutoConfiguration.java:107) [spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration.createClient(ElasticsearchAutoConfiguration.java:95) [spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration.elasticsearchClient(ElasticsearchAutoConfiguration.java:84) [spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$4638ae68.CGLIB$elasticsearchClient$1(<generated>) [spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$4638ae68$$FastClassBySpringCGLIB$$c4f7e2f3.invoke(<generated>) [spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) [spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) [spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration$$EnhancerBySpringCGLIB$$4638ae68.elasticsearchClient(<generated>) [spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) [spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) [spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE] at cn.xdf.springboot.Application.main(Application.java:18) [classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65] at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65] at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.5.9.RELEASE.jar:1.5.9.RELEASE]
添加依赖包即可,Idea在构建Springboot的时候少了这个包。
pom.xml
<dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <version>4.1.0</version> </dependency>