我有maven spring微服务和main类。
@EnableEncryptableProperties
@SpringBootApplication
@EnableDiscoveryClient
public class AccountService {
private static ApplicationContext applicationContext;
public static void main(String[] args) {
applicationContext = SpringApplication.run(AccountService.class, args);
}
}
在pom.xml中,我添加了以下用于注册应用程序的依赖项。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
在启动过程中,我得到以下错误。
[WARN ] 2021-01-11 22:05:50 [main] AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.microservices.accountservice.AccountService]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class] cannot be opened because it does not exist
[ERROR] 2021-01-11 22:05:50 [main] SpringApplication - Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.microservices.accountservice.AccountService]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.class] cannot be opened because it does not exist
该项目定义了以下春季版本。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
此外,微服务在启动过程中使用bootstrap.properties与spring cloud配置服务器进行通信,以获取application.properties。这个错误可能是什么问题?
pom.xml
中的依赖项彼此不兼容。您应该使用spring-cloud-starter-netflix-eureka-client:2.2.6.RELEASE
。
如果您不为每个依赖项指定版本,而是使用BOM(spring-cloud-dependencies
(,请参阅官方指南。