2014-02-06 62 views
0

我正在使用org.springframework.beans.factory.config.PropertyPlaceholderConfigurer来读取属性并加载它们。春季属性阅读器

我想打印由他们加载的所有属性,请帮忙吗?

+0

“print”...?从哪里来? – kryger

+0

你试过了什么?代码请 –

回答

1

如果您打算打印出PropertyPlaceholderConfigurer已加载和将要使用的属性,那么您可以最好将PropertyPlaceholderConfigurer子类化并自行注销属性。它很容易 - 例如:

public class LoggingPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer { 

    private static final Logger LOG = Logger.getLogger(LoggingPropertyPlaceholderConfigurer.class); 

    @Override 
    protected Properties mergeProperties() throws IOException { 
     Properties props = super.mergeProperties(); 
     for (String name : props.stringPropertyNames()) { 
      LOG.debug(name + ": " + props.getProperty(name)); 
     } 
     return props; 
    } 
} 

,然后更新您的Spring配置:

<bean class="LoggingPropertyPlaceholderConfigurer"> 
    <property name="location" value="classpath:myprops.properties"/> 
</bean> 
+0

我想在jsp文件上打印属性,就像我打电话一样,我应该能够打印它加载到网页的所有属性。 – geddamsatish

0

如果你使用log4j的,你可以通过添加记录它:

<logger name="org.springframework.beans.factory.config"> 
     <level value="info" /> 
</logger> 

它将显示:

INFO : org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from class path resource [myApp.properties]