SpringBoot文档之Profiles的阅读笔记

  • Reference

  • Core Features

  • Profiles
    类似Maven的Profile特性,限定配置项取值的生效场景。
    在代码中,对于使用注解@Component@Configuration@ConfigurationProperties标记的类,可以增加@Profile,限定前述类的生效场景。

    类似如下样例代码,当启动时指定Profileproduction时生效。

    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Profile;
    @Configuration(proxyBeanMethods = false)
    @Profile("production")
    public class ProductionConfiguration {
    // ...
    }

    SpringBoot框架定义了如下属性:

    • spring.profiles.active
    • spring.profiles.default
    • spring.config.activate.on-profile
    • spring.profiles.include

    可以通过配置文件、Java的系统属性、命令参数等方式来指定取值

    可以在代码中使用SpringApplication.setAdditionalProfiles显式指定当前可用的Profile

posted @   jackieathome  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示