打印通过Spring PropertyPlaceholderConfigurer设置的所有属性

Dar*_*nja 9 java spring

我想在启动时打印在我们的应用程序中设置的综合属性列表.做这个的最好方式是什么?

谢谢

fl4*_*l4l 5

这是我的实施:

public class CustomPropertySourcesPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer implements InitializingBean{

    public void afterPropertiesSet(){
        try{
            Properties loadedProperties = this.mergeProperties();
            for(Entry<Object, Object> singleProperty : loadedProperties.entrySet()){
                logger.info("LoadedProperty: "+singleProperty.getKey()+"="+singleProperty.getValue());
            }
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 对我不起作用,列表中根本没有属性. (5认同)

Dav*_*ton 4

使用重写方法并记录名称的自定义PropertyPlaceholderConfigurer实现。您可能还需要/想要覆盖这些方法,但应该处理它。resolve...placeholderconvert...resolve...