【问题标题】:spring boot configuration properties for a class in external jar外部jar中类的spring boot配置属性
【发布时间】:2017-06-21 10:00:15
【问题描述】:

我有一个 jar 文件,它有下面的类来加载一些属性 -

@ConfigurationProperties(prefix = "common-list")
@Configuration
@Component
public class CommonConfig{
...
}

在我的 spring boot 项目中,上面的 class/jar 是一个依赖项。
如何指定在我的项目中查找此属性“common-list”以加载的位置?

我是否需要修改类/jar,使用 PropertySource 注释指定在哪里查找这些公共列表值的属性文件?

我有以下行的 bootstrap.properties -

spring.application.name=xyz

配置服务器上的xyz.yaml

common-list:
...

通过查看我的 Spring Boot 应用程序的 env 属性,我可以看到文件已被拾取并加载。但是 CommonConfig 实例不会使用这些文件值进行初始化。

值组织正确,因为我通过在创建 jar 的同一项目中构建一个 spring boot 测试应用程序来测试它们(所有值都正确填充在 CommonConfig 实例中)。

更新(已解决)
问题是将我的对象错误地转换为 json 字符串,这导致建议进入默认路由而不是选择正确的值。

【问题讨论】:

    标签: spring spring-boot jar external properties-file


    【解决方案1】:

    当组件扫描获取到这个CommonConfig 类时,ConfigurationProperties 注释将基本上注入在application.ymlapplication.properties 中找到的以前缀common-list. 开头的属性并设置它们。

    查看 DZONE 文章 here

    【讨论】:

      【解决方案2】:

      我用分辨率更新了上面的帖子。
      问题不在于加载配置属性,而是加载代码。

      【讨论】:

        猜你喜欢
        • 2019-06-12
        • 1970-01-01
        • 2017-08-18
        • 1970-01-01
        • 2020-09-07
        • 1970-01-01
        • 1970-01-01
        • 2018-02-25
        • 2018-04-22
        相关资源
        最近更新 更多