简体   繁体   English

向JHipster Cloud application.yml添加属性会导致注册表配置失败

[英]Adding properties to JHipster Cloud application.yml causes registry configuration to fail

I want to add a custom property to the application.yml of my Cloud Config. 我想向我的Cloud Config的application.yml添加自定义属性。 The comments in the file say it is for all shared configuration. 文件中的注释说它适用于所有共享配置。 However, when I do so, it causes the binding of the properties to JHipsters own ApplicationProperties to fail at the class does not have the correct writable property. 但是,当我这样做时,它将导致属性与JHipsters自己的ApplicationProperty的绑定失败,因为该类没有正确的可写属性。

application.yml application.yml

application:
    clients:
        - Foo

Stacktrace: 堆栈跟踪:

Caused by: org.springframework.boot.bind.RelaxedBindingNotWritablePropertyException: Failed to bind 'application.clients[0]' from 'file:central-config/localhost-config/application.yml' to 'clients[0]' property on 'io.github.jhipster.registry.config.ApplicationProperties'

From JHipster's documentation: 从JHipster的文档中:

Application-specific properties Your generated application can also have its own Spring Boot properties. 特定于应用程序的属性生成的应用程序还可以具有其自己的Spring Boot属性。 This is highly recommended, as it allows type-safe configuration of the application, as well as auto-completion and documentation within an IDE. 强烈建议这样做,因为它允许对应用程序进行类型安全的配置,以及IDE中的自动完成和文档。

JHipster has generated a ApplicationProperties class in the config package, which is already preconfigured, and it is already documented at the bottom the application.yml, application-dev.yml and application-prod.yml files. JHipster已在config包中生成了一个ApplicationProperties类,该类已经预先配置,并且已经在文件application.yml,application-dev.yml和application-prod.yml的底部进行了说明。 All you need to do is code your own specific properties. 您所需要做的就是编写自己的特定属性。 (emphasis mine) (强调我的)

Have you done that step and added your own properties to ApplicationProperties.java ? 您已完成该步骤并将自己的属性添加到ApplicationProperties.java吗? It looks like you should have a property of type List<String> clients . 看起来您应该具有List<String> clients类型的属性。 If you haven't that's why it's failing, because it's attempting to bind a configuration property to the ApplicationProperties class, but the class doesn't contain a property to store it. 如果没有,那就是失败的原因,因为它试图将配置属性绑定到ApplicationProperties类,但是该类不包含用于存储它的属性。

Custom Spring boot properties should always be defined in a @ConfigurationProperties class within the app so that their value can be setup in the yml file. 自定义Spring引导属性应始终在应用程序的@ConfigurationProperties类中定义,以便可以在yml文件中设置它们的值。 This is thoroughly documented in the spring boot documentation: 在Spring Boot文档中对此进行了详细记录:

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM