Printing all properties set via Spring PropertyPlaceholderConfigurer

后端 未结 3 2062
执念已碎
执念已碎 2021-02-14 09:08

I’d like to print the consolidated list of properties set in our application on startup. What is the best way to do this?

Thanks

3条回答
  •  情歌与酒
    2021-02-14 09:37

    This is my implementation:

    public class CustomPropertySourcesPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer implements InitializingBean{
    
        public void afterPropertiesSet(){
            try{
                Properties loadedProperties = this.mergeProperties();
                for(Entry singleProperty : loadedProperties.entrySet()){
                    logger.info("LoadedProperty: "+singleProperty.getKey()+"="+singleProperty.getValue());
                }
            }catch(Exception ex){
                ex.printStackTrace();
            }
        }
    }
    

提交回复
热议问题