【问题标题】:Load a configuration file optionally depending on the environment-Production or Test根据环境选择加载配置文件 - 生产或测试
【发布时间】:2017-05-05 06:51:45
【问题描述】:

使用 Spring Profile,我们可以根据 @profile 注释加载特定的 bean。是否可以根据环境加载特定的配置类。实际上,配置类使用特定的注释进行注释,例如 @EnableSwagger,它总是被加载。并且有要求加载它可选。

谢谢

【问题讨论】:

    标签: spring spring-boot


    【解决方案1】:

    我有您描述的相同场景:我想在启用特定配置文件时启用 Swagger。使用配置文件没有任何问题:

    @Profile("API")
    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
    

    只有在我使用 API 配置文件时才会加载 SwaggerConfig。

    【讨论】:

    • 这是我想要的......谢谢。
    猜你喜欢
    • 2015-12-07
    • 2011-08-31
    • 1970-01-01
    • 2018-03-27
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-05
    相关资源
    最近更新 更多