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:

  • 相关阅读:
    JAVA变量的作用域
    SQLite
    ajax
    浏览器调试
    SQL链接
    Computer
    Sql知识点总结
    Web Socket
    秒杀
    副业
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14086249.html
Copyright © 2011-2022 走看看