我们的Spring applicationContext.xml中有这一行
<context:property-placeholder location="classpath*:*.properties" />但它并不是寻找和替换我们认为应该是的特定属性价值。我们有没有办法让这个特殊的属性占位符告诉我们它正在查找的路径,它正在查找的文件以及它正在查看的属性?
发布于 2011-05-05 21:09:15
您可以子类化PropertyPlaceHolderConfigurer,如下所示:
public class LoggingPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
@Override
public void setLocations(final Resource[] locations) {
if(logger.isDebugEnabled())
for (final Resource resource : locations) {
logger.debug("Using resource: " + resource);
}
super.setLocations(locations);
}
@Override
protected Properties mergeProperties() throws IOException {
final Properties mergedProperties = super.mergeProperties();
if(logger.isDebugEnabled())
for (final Entry<String, Object> propertyEntry :
new TreeMap<String, Object>((Map) mergedProperties).entrySet()) {
logger.debug(
"Key:" + propertyEntry.getKey()
+ ", value:" + propertyEntry.getValue());
}
return mergedProperties;
}
}现在手动连接您的自定义类(命名空间不起作用):
<bean class="path.to.LoggingPlaceholderConfigurer">
<property name="locations" value="classpath*:*.properties" />
</bean>并设置日志记录配置,以便为LoggingPlaceholderConfigurer激活日志级调试
(这是<context:property-placeholder>的临时替代品,仅用于调试目的)
发布于 2011-05-05 19:53:02
我不这么认为,但是您可以通过调用System.getProperty("java.class.path")来获取当前的类路径
发布于 2011-05-05 20:05:31
您可以将spring框架源代码附加到您的项目中,并使用调试,您可以查看找到/读取了哪些属性文件。我认为这是一个项目配置/打包/部署问题。尝试复制您的属性文件,比如my.properties,然后放入其中一个包中,看看它是否正常工作。如果它可以工作,那么你需要重新配置你的类路径。
https://stackoverflow.com/questions/5896659
复制相似问题