Java 我能买春天的吗;s<;上下文:属性占位符/>;告诉我它是什么类路径';他在找什么?

Java 我能买春天的吗;s<;上下文:属性占位符/>;告诉我它是什么类路径';他在找什么?,java,spring,classpath,Java,Spring,Classpath,我们的SpringapplicationContext.xml中有这一行: <context:property-placeholder location="classpath*:*.properties" /> 但它并没有发现并取代我们认为应该具有的特定财产价值。我们有没有办法让这个特定的属性占位符告诉我们它正在查找的路径、它正在查找的文件以及它正在查看的属性?我不这么认为,但是您可以通过调用System.getProperty(“java.class.path”)来获取当前的

我们的Spring
applicationContext.xml中有这一行:

<context:property-placeholder location="classpath*:*.properties" />


但它并没有发现并取代我们认为应该具有的特定财产价值。我们有没有办法让这个特定的属性占位符告诉我们它正在查找的路径、它正在查找的文件以及它正在查看的属性?

我不这么认为,但是您可以通过调用
System.getProperty(“java.class.path”)
来获取当前的类路径,但是您可以通过调用
System.getProperty(“java.class.path”)

来获取当前的类路径。您可以将spring框架源代码附加到您的项目中,并使用调试,您可以看到找到/读取了哪些属性文件。我认为这是一个项目配置/打包/部署问题。试着复制你的属性文件,比如my.properties,然后放入其中一个包中,看看它是否工作。如果可以,那么您需要重新配置类路径。

您可以将spring框架源附加到项目中,并使用调试,您可以看到找到/读取了哪些属性文件。我认为这是一个项目配置/打包/部署问题。试着复制你的属性文件,比如my.properties,然后放入其中一个包中,看看它是否工作。如果它有效,那么您需要重新配置类路径。

您可以将PropertyPlaceHolderConfigure子类化,如下所示:

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;
    }

}
公共类LoggingPlaceholderConfigurer扩展了PropertyPlaceholderConfigurer{
@凌驾
公共void集合位置(最终资源[]位置){
if(logger.isDebugEnabled())
用于(最终资源:位置){
调试(“使用资源:“+resource”);
}
超级设置位置(位置);
}
@凌驾
受保护的属性mergeProperties()引发IOException{
最终属性mergedProperties=super.mergeProperties();
if(logger.isDebugEnabled())
对于(最终输入属性输入:
新树映射((映射)mergedProperties.entrySet()){
logger.debug(
“键:”+propertyEntry.getKey()
+,值:“+propertyEntry.getValue());
}
归还财产;
}
}
现在手动连接自定义类(命名空间将不起作用):


并设置日志记录配置,以便日志级调试对于
LoggingPlaceholderConfigurer


(这只是为了调试目的而临时替换

您可以将
属性PlaceHolderConfigure
子类化,如下所示:

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;
    }

}
公共类LoggingPlaceholderConfigurer扩展了PropertyPlaceholderConfigurer{
@凌驾
公共void集合位置(最终资源[]位置){
if(logger.isDebugEnabled())
用于(最终资源:位置){
调试(“使用资源:“+resource”);
}
超级设置位置(位置);
}
@凌驾
受保护的属性mergeProperties()引发IOException{
最终属性mergedProperties=super.mergeProperties();
if(logger.isDebugEnabled())
对于(最终输入属性输入:
新树映射((映射)mergedProperties.entrySet()){
logger.debug(
“键:”+propertyEntry.getKey()
+,值:“+propertyEntry.getValue());
}
归还财产;
}
}
现在手动连接自定义类(命名空间将不起作用):


并设置日志记录配置,以便日志级调试对于
LoggingPlaceholderConfigurer

(这是对
的临时替换,仅用于调试目的)