【问题标题】:Binding application.properties to a class from external library in Spring将 application.properties 绑定到 Spring 中外部库中的类
【发布时间】:2022-11-16 22:34:52
【问题描述】:

假设我有一个具有这个简单类的外部 jar(应该在 spring boot env 中工作):

@Component
@ConfigurationProperties("test")
public class NetworkConfig {
  //getters/setters
...
}

现在我在 Spring 项目中使用这个 jar 作为 dep (不是弹簧靴!).

我在那个项目中有一个 application.properties 文件,想从它加载属性到这个类,它应该在上下文中可用。我该怎么做?

我还需要提到外部 jar 是我的库,如果需要我可以修改它。

【问题讨论】:

  • 如果该类已被注释为配置属性,则您只需要@EnableConfigurationProperties
  • @AbhijitSarkar 好吧,重点是父项目是 Spring 而不是前面提到的 spring boot:@EnableConfigurationProperties 是 spring boot 的一部分。

标签: java spring spring-boot


【解决方案1】:

@ConfigurationPropertiesScan ("path_to_property")

【讨论】:

    猜你喜欢
    • 2014-08-09
    • 2017-10-22
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-10
    • 2019-07-16
    • 2013-04-02
    相关资源
    最近更新 更多