Java中怎么获取spring中配置的properties属性文件内容

Java中如何获取spring中配置的properties属性文件内容1、通过spring配置properties文件 bean idproperty

Java中如何获取spring中配置的properties属性文件内容

1、通过spring配置properties文件

 



其中class为自己定义的类

2、自定义类CustomizedPropertyPlaceholderConfigurer

 

 


这样就可以通过CustomizedPropertyPlaceholderConfigurer类来获取properties属性文件中的内容了

3、如何获取属性文件的内容

String host =  (String) CustomizedPropertyPlaceholderConfigurer.getContextProperty("mail.smtp.host");