是否可以简单地记录 spring 加载的属性文件的所有内容<context:property-placeholder />
?
谢谢
您可以将日志级别设置org.springframework.core.env.PropertySourcesPropertyResolver
为“调试”。然后,您将能够在解析过程中看到属性的值。
你可以这样做:
<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());
}
}
}