How to use Java property files?

后端 未结 17 1367
时光取名叫无心
时光取名叫无心 2020-11-22 11:13

I have a list of key/value pairs of configuration values I want to store as Java property files, and later load and iterate through.

Questions:

  • Do I ne
17条回答
  •  攒了一身酷
    2020-11-22 11:42

    in my opinion other ways are deprecated when we can do it very simple as below:

    @PropertySource("classpath:application.properties")
    public class SomeClass{
    
        @Autowired
        private Environment env;
    
        public void readProperty() {
            env.getProperty("language");
        }
    
    }
    

    it is so simple but i think that's the best way!! Enjoy

提交回复
热议问题