【问题标题】:How to create custom annotation that will add new property source如何创建将添加新属性源的自定义注释
【发布时间】:2016-07-21 14:38:54
【问题描述】:

我有几个 Spring Boot 应用程序,我想在其中放置一个自定义注释(在某些 bean 中)。注释将有一个字段(例如 propertyValue)。我想将该值作为新 PropertySource 的一部分添加到环境中。

我的想法是创建一个注入 Environment 的 bean,然后向其中添加一个新的 PropertySource。缺少的部分是如何将自定义注解与这个 bean 连接起来。

有什么想法吗?

【问题讨论】:

  • 基本上你想让 Spring 了解自定义 Annotation 对吧?
  • 是的,并使用注释中传递的值执行bean方法。
  • 为什么标准注释不适合你?
  • 我不想从文件中读取属性源。

标签: java spring spring-boot annotations


【解决方案1】:

所以你想为不同的环境使用不同的属性文件。 Spring Boot 已经处理了这个问题,不需要自定义 bean 或注释。

只需使用Profile-Specific Configuration Spring Boot 功能。您可以通过系统属性定义配置文件(例如-Dspring.profiles.active=PROD-US-EAST-REGION

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-09
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 2022-06-20
    相关资源
    最近更新 更多