如何解决无法初始化 Eureka servlet 上下文 pom.xmlapplication.ymlshared/discovery-service.ymlpom.xml主要网关发现配置
我正在将我的实际项目升级到 Spring Boot 2.5.2。 我有一个配置服务器、一个 zuul 网关和一个发现服务器。 现在我看到 Spring Cloud 在我的发现服务器中有一个嵌入式网关,我想使用它。所以我最后只有配置服务器和发现服务器(包括我的网关) 但我从发现服务器获得以下堆栈跟踪:
08-07-2021 14:03:46.449 [Thread-11] INFO c.n.e.r.PeerAwareInstanceRegistryImpl.openForTraffic - Got 1 instances from neighboring DS node
08-07-2021 14:03:46.449 [Thread-11] INFO c.n.e.r.PeerAwareInstanceRegistryImpl.openForTraffic - Renew threshold is: 1
08-07-2021 14:03:46.449 [Thread-11] INFO c.n.e.r.PeerAwareInstanceRegistryImpl.openForTraffic - Changing status to UP
08-07-2021 14:03:46.467 [Thread-11] ERROR o.s.c.n.e.s.EurekaServerBootstrap.contextinitialized - Cannot bootstrap eureka server :
java.lang.NullPointerException: null
at org.springframework.cloud.netflix.eureka.server.EurekaServerBootstrap.contextinitialized(EurekaServerBootstrap.java:73)
at org.springframework.cloud.netflix.eureka.server.EurekaServerInitializerConfiguration.lambda$start$0(EurekaServerInitializerConfiguration.java:68)
at java.lang.Thread.run(Thread.java:748)
08-07-2021 14:03:46.468 [Thread-11] ERROR o.s.c.n.e.s.EurekaServerInitializerConfiguration.lambda$start$0 - Could not initialize Eureka servlet context
java.lang.RuntimeException: Cannot bootstrap eureka server :
at org.springframework.cloud.netflix.eureka.server.EurekaServerBootstrap.contextinitialized(EurekaServerBootstrap.java:77)
at org.springframework.cloud.netflix.eureka.server.EurekaServerInitializerConfiguration.lambda$start$0(EurekaServerInitializerConfiguration.java:68)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: null
at org.springframework.cloud.netflix.eureka.server.EurekaServerBootstrap.contextinitialized(EurekaServerBootstrap.java:73)
... 2 common frames omitted
这是我的代码:
配置服务器:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.geminiald</groupId>
<artifactId>config-service</artifactId>
<version>2.1.0</version>
<name>config-service</name>
<description>Configuration service</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.yml
spring:
cloud:
config:
server:
native:
search-locations: classpath:/shared
profiles:
active: native
security:
user:
password: configPassword
server:
port: 8081
shared/discovery-service.yml
server:
port: 8082
logging:
level:
org:
hibernate:
sql: DEBUG
type:
descriptor:
sql:
BasicBinder: TRACE
发现服务器
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.geminiald</groupId>
<artifactId>discovery-service</artifactId>
<version>2.1.0</version>
<name>discovery-service</name>
<description>discovery service</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
主要
@SpringBootApplication
@EnableEurekaServer
public class discoveryServiceApplication {
public static void main(String[] args) {
SpringApplication.run(discoveryServiceApplication.class,args);
}
}
网关发现配置
@Configuration
@EnablediscoveryClient
public class GatewaydiscoveryConfiguration {
@Bean
public discoveryClientRouteDeFinitionLocator
discoveryClientRouteLocator(ReactivediscoveryClient discoveryClient,discoveryLocatorProperties locatorProperties) {
return new discoveryClientRouteDeFinitionLocator(discoveryClient,locatorProperties);
}
}
如果有人能帮助我,我将不胜感激。
提前致谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。