Reading values from application.properties Spring Boot

后端 未结 10 1757
无人及你
无人及你 2021-01-18 10:46

My Spring boot app has this application structure:

  • src
    • main
      • java
      • resources
        • application.properties
      <
10条回答
  •  别那么骄傲
    2021-01-18 11:30

    you can try to use @PropertySource and give it the path to property file, you can find the sample below:

    @Component
    @PropertySource("classpath:application.properties")
    public class EntityManager {
    
        @Value("${language}")
        private static String newLang;
    
        public EntityManager(){
            System.out.println("langauge is: " + newLang);
        }
    }
    

提交回复
热议问题