application.properties中的空值导致“无法解析占位符”异常
问题描述:
我们得到了一个spring-boot应用程序,它从配置服务器读取它的配置。application.properties中的空值导致“无法解析占位符”异常
我在使用spring-cloud-configuration-server读取空属性时遇到了问题。
设置是在application.properties中没有值的KV对。 例如 MyKey =
仅使用文件加载它“常规”没有问题引发。
但是,当客户端使用的配置服务器,空值导致:
“java.lang.IllegalArgumentException异常:无法解析占位符‘的myKey’”。
寻找我配置服务器中有些奇怪的东西。 因此,这里是它的application.yml:
info:
version: '@[email protected]'
artifact: '@[email protected]'
server:
port: 10805
spring:
application:
name: ${info.artifact}
http:
encoding:
charset: UTF-8
boot:
admin:
discovery:
enabled: true
context-path: /admin
jmx:
enabled: false
endpoints:
jmx:
enabled: false
turbine:
combineHostPort: true
app-config: service.us
clusterNameExpression: "'default'"
---
spring:
profiles: win
eureka:
server:
disable-delta: true
disable-delta-for-remote-regions: true
instance:
hostname: ${COMPUTERNAME}
client:
serviceUrl:
defaultZone: http://localhost:10805/eureka/
archaius:
deployment:
datacenter: ${eureka.instance.hostname}
environment: local
---
spring:
profiles: default
eureka:
instance:
virtual-host-name: ${eureka.instance.appname}
app-group-name: ces
appname: admin.ces
---
spring:
profiles:
active: subversion
cloud:
config:
server:
svn:
uri : https://myserver/svn/ces/trunk/config/
username: conf
password: ****
什么想法?
答
我终于找到了问题。
配置服务器也驱动一个eureka服务器。 这种组合导致上述行为。
删除批注和依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
解决了这个问题。
所以我们的想法在同一个实例上运行这两个服务目前是不可实现的。
二手版本:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.RS4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>