【问题标题】:Empty value in application.properties leads to "Could not resolve placeholder" exceptionapplication.properties 中的空值导致“无法解析占位符”异常
【发布时间】:2017-02-19 02:18:04
【问题描述】:

我们有一个 spring-boot 应用程序,它从配置服务器读取它的配置。

我在使用 spring-cloud-configuration-server 读取空属性时遇到问题。

设置是一个 KV 对,在 application.properties 中没有值。 例如 我的钥匙=

仅使用文件“常规”加载它不会出现问题。

但是当客户端使用配置服务器时,空值会导致:

“java.lang.IllegalArgumentException:无法解析占位符'MyKey'”。

在我看来,配置服务器中有一些奇怪的东西。 所以这里是它的application.yml:

info:
  version: '@project.version@'
  artifact: '@project.artifactId@'
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: ****

有什么想法吗?

【问题讨论】:

    标签: java spring spring-boot configuration server


    【解决方案1】:

    我终于找到了问题。

    配置服务器也驱动一个尤里卡服务器。 这种组合会导致上述行为。

    删除注解和依赖

        <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>
    

    【讨论】:

      猜你喜欢
      • 2021-06-23
      • 2018-06-13
      • 2020-04-01
      • 2017-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-20
      相关资源
      最近更新 更多