在我的SpringBoot应用程序中启动ApplicationContext时出现以下错误:
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) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:50) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:348) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:151) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:114) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:880) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
at es.ual.acg.cos.abstractcomponents.AbstractcomponentsApplication.main(AbstractcomponentsApplication.java:12) [classes/:na]
Caused by: java.lang.NullPointerException: null
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:56) ~[spring-cloud-netflix-eureka-client-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:37) ~[spring-cloud-netflix-eureka-client-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:80) ~[spring-cloud-netflix-eureka-client-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
... 14 common frames omitted
我已经在主类中启用了带有装饰器@EnableEurekaClient
的Eureka 客户端。
我有configure。属性文件,包含:
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
eureka.instance.preferIpAddress=true
我用途:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
首先,我已经在其他Sping Boot 项目中运行了Eureka Server(它工作正常)。
注意:这是主类:
package es.ual.acg.cos.abstractcomponents;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication(scanBasePackages={"es.ual.acg.cos.abstractcomponents", "es.ual.acg.cos.util"})
@EnableEurekaClient
public class AbstractcomponentsApplication {
public static void main(String[] args) {
SpringApplication.run(AbstractcomponentsApplication.class, args);
}
}
3条答案
按热度按时间nuypyhwy1#
我也遇到了同样的问题,对我来说原因是版本冲突。
我的springboot版本是1。5.9.RELEASE,我的项目maven依赖关系中止如下:
原因是因为我引入了httpcomponents,它的版本是4。2.1,但与Eureka 推出的httpcomponents版本不同(版本为httpclient/4.5.3和httpcore/4。4.6,你可以使用mvn dependency:tree来检查),我认为是导致bean 'eurekaAutoServiceRegistration'失败的原因。
最后我把httpclient的版本改成了4。5.3和httpcore到4。4.6,那就管用了,希望对你有帮助^_^
5us2dqdw2#
如果应用程序用于Eureka 客户端,则删除Eureka服务器依赖项
spring-cloud-starter-netflix-eureka-server
。原因:
在Eureka 客户端应用程序中,如果存在不需要的服务器依赖项
spring-cloud-starter-netflix-eureka-server
,则可能会发生此错误。然而,原因也可能是因为失败的bean创建(使用如下所示的stacktrace):
删除与Eureka 服务器相关的依赖项,并仅具有客户端依赖项
spring-cloud-starter-netflix-eureka-client
可以潜在地解决此问题。我在Sping Boot v2中遇到了这种情况。7.8(Spring Cloud。版本v2021。0.3)。
wqnecbli3#
也许,您使用其他json反序列化依赖项。Jackson是Spring Cloud的默认序列化依赖项。
可能是
我通过删除这个依赖项来解决这个问题。