Spring JavaConfig for java.util.Properties field

后端 未结 6 2059
面向向阳花
面向向阳花 2021-02-13 02:07


Can you please tell me how to use Spring Javaconfig to directly load/autowire a properties file to a java.util.Properties field?

Thanks!

Later edit - st

6条回答
  •  鱼传尺愫
    2021-02-13 02:42

    It is an old subject but there are also a more basic solution.

    @Configuration
    public class MyConfig {
        @Bean
        public Properties myPropertyBean() {
            Properties properties = new Properties();
            properties.load(...);
            return properties;
        }
    }
    

提交回复
热议问题