13

是否可以简单地记录 spring 加载的属性文件的所有内容<context:property-placeholder />

谢谢

4

2 回答 2

12

您可以将日志级别设置org.springframework.core.env.PropertySourcesPropertyResolver为“调试”。然后,您将能够在解析过程中看到属性的值。

于 2014-07-17T04:45:20.403 回答
2

你可以这样做:

<context:property-placeholder properties-ref="myProperties"/>

<bean id="myProperties"
      class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="locations">
    <list>
      .. locations
    </list>
  </property>
</bean>

并添加一个类似于下面的日志记录bean(这里基于注释并使用slf4j api):

@Component
public class PropertiesLogger {
  private static Logger logger = LoggerFactory.getLogger(PropertiesLogger.class);

  @Resource("myProperties")
  private Properties props;

  @PostConstruct
  public void init() {
    for (Map.Entry<Object, Object> prop : props.entrySet()) {
      logger.debug("{}={}", prop.getKey(), prop.getValue());
    }
  }
}
于 2013-01-13T13:44:32.353 回答