Spring JavaConfig for java.util.Properties field

后端 未结 6 2064
面向向阳花
面向向阳花 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:43

    You can try this

    @Configuration  
    public class PropertyConfig { 
    
     @Bean("mailProperties")  
     @ConfigurationProperties(prefix = "mail")   
      public Properties getProperties() {
         return new Properties();  
      }
    
    }
    

    Make sure to define properties in application.properties

提交回复
热议问题