Spring Boot 项目启动正常,加入Spring Cloud后启动失败,报错
2017-09-18 18:02:22.837 ERROR [ main] o.s.c.n.e.s.EurekaRegistration:124 - error getting CloudEurekaClient
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.eurekaClient' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.discovery.EurekaClient]: Factory method 'eurekaClient' threw exception; nested exception is java.lang.RuntimeException: Failed to initialize DiscoveryClient!
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:345)
at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:359)
at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:176)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:340)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getTargetObject(EurekaRegistration.java:133)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient(EurekaRegistration.java:122)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:56)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:37)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:73)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175)
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:114)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:880)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.mzw.lottery.Application.main(Application.java:32)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.discovery.EurekaClient]: Factory method 'eurekaClient' threw exception; nested exception is java.lang.RuntimeException: Failed to initialize DiscoveryClient!
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 30 common frames omitted
Caused by: java.lang.RuntimeException: Failed to initialize DiscoveryClient!
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:405)
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:266)
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:262)
at org.springframework.cloud.netflix.eureka.CloudEurekaClient.<init>(CloudEurekaClient.java:60)
at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.eurekaClient(EurekaClientAutoConfiguration.java:228)
at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$a10f1fa2.CGLIB$eurekaClient$0(<generated>)
at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$a10f1fa2$$FastClassBySpringCGLIB$$5e9e7e6e.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$a10f1fa2.eurekaClient(<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:162)
... 31 common frames omitted
Caused by: java.lang.RuntimeException: Cannot create Jersey client
at com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl$EurekaJerseyClientBuilder.build(EurekaJerseyClientImpl.java:174)
at com.netflix.discovery.shared.transport.jersey.JerseyEurekaHttpClientFactory$JerseyEurekaHttpClientFactoryBuilder.buildLegacy(JerseyEurekaHttpClientFactory.java:197)
at com.netflix.discovery.shared.transport.jersey.JerseyEurekaHttpClientFactory$JerseyEurekaHttpClientFactoryBuilder.build(JerseyEurekaHttpClientFactory.java:178)
at com.netflix.discovery.shared.transport.jersey.JerseyEurekaHttpClientFactory.create(JerseyEurekaHttpClientFactory.java:135)
at com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories.newTransportClientFactory(Jersey1TransportClientFactories.java:48)
at com.netflix.discovery.DiscoveryClient.scheduleServerEndpointTask(DiscoveryClient.java:454)
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:392)
... 45 common frames omitted
Caused by: java.lang.RuntimeException: Cannot create Jersey client
at com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl.<init>(EurekaJerseyClientImpl.java:60)
at com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl$EurekaJerseyClientBuilder.build(EurekaJerseyClientImpl.java:172)
... 51 common frames omitted
Caused by: com.sun.jersey.spi.inject.Errors$ErrorMessagesException: null
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
at com.sun.jersey.api.client.Client.<init>(Client.java:188)
at com.sun.jersey.client.apache4.ApacheHttpClient4.<init>(ApacheHttpClient4.java:151)
at com.sun.jersey.client.apache4.ApacheHttpClient4.<init>(ApacheHttpClient4.java:137)
at com.sun.jersey.client.apache4.ApacheHttpClient4.create(ApacheHttpClient4.java:181)
at com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl.<init>(EurekaJerseyClientImpl.java:52)
... 52 common frames omitted
2017-09-18 18:02:22.852 WARN [ main] o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext:551 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration'; nested exception is java.lang.NullPointerException
2017-09-18 18:02:22.852 INFO [ main] o.s.b.a.e.jmx.EndpointMBeanExporter:449 - Unregistering JMX-exposed beans on shutdown
2017-09-18 18:02:22.852 INFO [ main] o.s.j.e.a.AnnotationMBeanExporter:449 - Unregistering JMX-exposed beans on shutdown
2017-09-18 18:02:22.852 INFO [ main] o.s.j.e.a.AnnotationMBeanExporter:241 - Unregistering JMX-exposed beans
2017-09-18 18:02:22.852 INFO [ main] o.s.o.j.LocalContainerEntityManagerFactoryBean:548 - Closing JPA EntityManagerFactory for persistence unit 'default'
2017-09-18 18:02:22.852 INFO [ main] o.a.catalina.core.StandardService:179 - Stopping service [Tomcat]
2017-09-18 18:02:22.868 INFO [ main] o.s.b.a.l.AutoConfigurationReportLoggingInitializer:101 -
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-09-18 18:02:22.868 ERROR [ main] o.s.boot.SpringApplication:771 - Application startup failed
org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration'; nested exception is java.lang.NullPointerException
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:114)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:880)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at com.mzw.lottery.Application.main(Application.java:32)
Caused by: java.lang.NullPointerException: null
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:56)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:37)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:73)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175)
... 14 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:65276', transport: 'socket'
Process finished with exit code 1
配置文件如下:
@SpringBootApplication
@EnableDiscoveryClient
@EnableWebSecurity
@EnableTransactionManagement
public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer {
private static Logger logger = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) {
logger.info("--------------------------------------------");
logger.info("------------------application start--------------------------");
SpringApplication.run(Application.class, args);
logger.info("-------------------application end-------------------------");
logger.info("--------------------------------------------");
}
@Override
public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) {
logger.info("--------------------------------------------");
logger.info("------------------customize start--------------------------");
// configurableEmbeddedServletContainer.setPort(8088);
logger.info("-------------------customize end-------------------------");
logger.info("--------------------------------------------");
}
}
############################### SPRING CLOUD
eureka:
client:
serviceUrl:
defaultZone: http://localhost:62270/eureka
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
2017-09-2216:44:05.919INFO[main]c.s.j.c.s.component.ProviderServices:348-Providerfound:classcom.sun.jersey.core.impl.provider.entity.StreamingOutputProvider2017-09-2216:44:05.919INFO[main]c.s.j.c.s.component.ProviderServices:348-Providerfound:classcom.sun.jersey.core.impl.provider.entity.SourceProvider$SourceWriter2017-09-2216:44:05.919INFO[main]c.s.j.c.s.component.ProviderFactory:173-Adependentclass,javax/mail/MessagingException,ofthecomponentclasscom.sun.jersey.core.impl.provider.entity.MimeMultipartProviderisnotfound.Thecomponentisignored.2017-09-2216:44:05.935ERROR[main]com.sun.jersey.spi.inject.Errors:168-Thefollowingerrorsandwarningshavebeendetectedwithresourceand/orproviderclasses:SEVERE:Missingdependencyforfield:javax.ws.rs.core.UriInfocom.alibaba.fastjson.support.jaxrs.FastJsonProvider.uriInfo2017-09-2216:44:05.935WARN[main]o.s.b.f.s.DisposableBeanAdapter:347-Invocationofdestroymethod'close'failedonbeanwithname'eurekaRegistration':org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'scopedTarget.eurekaClient'definedinclasspathresource[org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]:Beaninstantiationviafactorymethodfailed;nestedexceptionisorg.springframework.beans.BeanInstantiationException:Failedtoinstantiate[com.netflix.discovery.EurekaClient]:Factorymethod'eurekaClient'threwexception;nestedexceptionisjava.lang.RuntimeException:FailedtoinitializeDiscoveryClient!2017-09-2216:44:05.935INFO[main]o.s.o.j.LocalContainerEntityManagerFactoryBean:561-ClosingJPAEntityManagerFactoryforpersistenceunit'default'2017-09-2216:44:05.950INFO[main]o.a.catalina.core.StandardService:179-Stoppingservice[Tomcat]2017-09-2216:44:05.966WARN[main]o.s.b.c.e.EventPublishingRunListener:133-ErrorcallingApplicationEventListenerjava.lang.ClassCastException:org.springframework.boot.context.event.ApplicationFailedEventcannotbecasttoorg.springframework.boot.web.context.WebServerInitializedEventatorg.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:159)atorg.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)atorg.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)atorg.springframework.boot.context.event.EventPublishingRunListener.finished(EventPublishingRunListener.java:114)
把所有日志调为DEBUG后,终于找到了原因:
2017-09-2216:44:05.935ERROR[main]com.sun.jersey.spi.inject.Errors:168-Thefollowingerrorsandwarningshavebeendetectedwithresourceand/orproviderclasses:SEVERE:Missingdependencyforfield:javax.ws.rs.core.UriInfocom.alibaba.fastjson.support.jaxrs.FastJsonProvider.uriInfo
因为项目中使用了FastJson,引用的版本为1.2.18,和jsr311-api有冲突,所以导致问题,暂时的解决办法是把项目中的fastjson改用jackson
各位大大侠有什么更好的办法解决吗?换fastjson,要更改的地方太多了,简直就是恶梦~~
经过四天的查找,终于找到了问题,希望可以帮到有想要的人吧。看到一篇文章http://blog.csdn.net/badyting/article/details/72822660jackson和spring高度集成,没有任何理由用其他jar代替,自找苦吃
已经换成jackson了使用jackson吧,与spring集成好一点
已经换了版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。