cannot resolve configuration property 'eureka.client.serviceUrl.defaultZone'
程序员文章站
2022-07-14 23:49:23
...
编写微服务时候eureka客户端进行注册服务yml也引入也相关配置一切配置Ok,奇怪的是该客户端服务启动成功所有接口通过ip也能正常访问但是一直不能注册到EurekaServer中心,相同的配置在其他项目中就是好的。然后application.yml文件一直提示“cannot resolve configuration property 'eureka.client.serviceUrl.defaultZone' more...(Ctrl+F1)”,Eureka相关的属性全部提示
错误原因:未找到配置相关属性
解决方案:
一、删除Eureka相关依赖,重新编译后再重新添加再编译(这种方法试过了很多遍也不好使)
二、参考官网https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/html/configuration-metadata.html#configuration-metadata-annotation-processor添加配置识别属性(用这种方法是Ok的)
1、添加相关依赖
- gradle项目依赖
compileOnly "org.springframework.boot:spring-boot-configuration-processor"
- maven项目引入依赖
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-configuration-processor -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
2、在resoures/META-INF文件夹下新增文件additional-spring-configuration-metadata.json,内容如下
{
"properties": [
{
"name": "eureka.client.serviceUrl.defaultZone",
"type": "java.lang.String",
"description": "Description for eureka.client.serviceUrl.defaultZone."
}
] }
3、在application.java添加引入该文件属性相关注解 @ConfigurationProperties
4、再次编译启动发现服务注册成功了
上一篇: MySQL双主双从集群搭建
推荐阅读
-
Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframewor
-
Error:Could not resolve all dependencies for configuration ':app:prodDebugCompileClasspath'. Cannot
-
cannot resolve configuration property 'eureka.client.serviceUrl.defaultZone'
-
Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframewor