zoukankan      html  css  js  c++  java
  • [Java Spring] @Value & override properties by environment variables

    We can have some properties defined inside application.properties or application.yml file.

    application.properties:

    app.name=Frank
    app.greeting=Hello

    We can get those value by @Value:

    @Configuration
    @PropertySource("classpath:application.properties")
    public class ApplicationConfig {
    
        @Value("${app.greeting}")
        private String greeting;
        @Value("${app.name}")
        private String name;
    
       ...
    
    }

    @PropertySource is used to defined where to looking for application.properties file. Normally it should be located in 'resources' folder.

    'classpath': points to 'resources' folder.

    Environment variable:

    we can also override those properties by environment varialbe:

  • 相关阅读:
    OpenJudge 6042 雇佣兵
    POJ 1741 树上 点的 分治
    Codevs 1695 Windows2013
    复制书稿
    乘积最大
    编辑距离问题
    石子合并
    最大正方形子矩阵
    选菜
    混合背包
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14086249.html
Copyright © 2011-2022 走看看