无法解析占位符

3
当我运行junit测试用例时,出现以下错误:
Invalid bean definition with name 'CacheRegionManagerFactory' defined in class path resource [com/bgc/ecm/core/caching/cacheRegionManager-ctx.xml]: Could not resolve placeholder 'appRoot'

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'CacheRegionManagerFactory' defined in class path resource [com/bgc/ecm/core/caching/cacheRegionManager-ctx.xml]: Could not resolve placeholder 'appRoot'
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:268)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)

cacheRegionManager-ctx.xml文件:

<bean id="CacheRegionManagerFactory" class="com.bgc.ecm.core.caching.CacheRegionManagerFactory">
          <property name="diskStoreCachePath" value="${diskStoreCacheRootPath}/${appRoot}/was/var/elnino/${appName}/${cloneNumber}"/>
        <property name="defaultRegion" ref="DefaultRegion"/>
        <property name="regionInfos" ref="CustomRegions"/>                
    </bean>  

propertyContext.xml:

<context:property-placeholder 
               location="classpath:/property/globalContext.properties,     
                       classpath:/property/globalContext-${app.env}.properties,
                       classpath:/property/globalContext-${app.env}-${app.module}.properties,    
                       classpath:/property/applicationContext.properties,
                       classpath:/property/applicationContext-${app.module}.properties,         
                       classpath:/property/applicationContext-${app.env}.properties,           
                       classpath:/property/applicationContext-${app.env}-${app.module}.properties"/>  

并且applicationContext-DEV-FNT.properties包含:

appName=bgc-elnino-core-cluster
appRoot=ecm
cloneNumber=1
site=elnino-core 

Junit目标:

<target name="junit" depends="init-junit">
    <copy todir="${TEST_BUILD_DIR}/" overwrite="true">
        <fileset dir="${COMP_TESTCONFIG_DIR}">
            <exclude name="*.properties.template" />
        </fileset>
    </copy> 
    <junit printsummary="on" fork="yes" forkmode="perBatch" haltonfailure="false" failureproperty="junit.failure" showoutput="false">           
        <classpath>
            <path refid="CLASSPATH_JUNIT"/>             
        </classpath>            
        <batchtest fork="no"  todir="${TEST_BUILD_DIR}">
           <fileset dir="${COMP_TEST_SRC}" erroronmissingdir="false">                             
              <include name="**/*Test.java" />
                  <include name="**/Test*.java" />                          
           </fileset>              
        </batchtest>
        <formatter type="xml" />
    </junit>    
    <junitreport todir="${JUNIT_REPORT}">
        <fileset dir="${TEST_BUILD_DIR}">
            <include name="TEST-*.xml" />           
        </fileset>       
        <report format="frames" todir="${JUNIT_REPORT}"/>       
    </junitreport>      
    <delete dir="${TEST_BUILD_DIR}" />  

</target>   

环境变量是:
public final void setupEnvironmentPropertiesIfNeeded()
{
    String address = (new StringBuilder()).append("@").append(Integer.toHexString(System.identityHashCode(this))).toString();
    if(StringUtils.isEmpty(System.getProperty("app.env")))
    {
        LOG.info((new StringBuilder()).append(address).append(" Environment property app.env will be set to DEV").toString());
        System.setProperty("app.env", "DEV");
    } else
    {
        LOG.info((new StringBuilder()).append(address).append(" Environment property app.env already set to:'").append(System.getProperty("app.env")).append("'").toString());
    }
    if(StringUtils.isEmpty(System.getProperty("app.module")))
    {
        LOG.info((new StringBuilder()).append(address).append(" Environment property app.module will be set to FNT").toString());
        System.setProperty("app.module", "FNT");
    } else
    {
        LOG.info((new StringBuilder()).append(address).append(" Environment property app.module already set to:'").append(System.getProperty("app.module")).append("'").toString());
    }
}

你的 ${app.env} 和 ${app.module} 属性是如何解析的? - abalogh
1
${app.env}和${app.module}是如何填充的? - Ralph
1
你确定指定的applicationContext-DEV-FNT.properties被加载了吗?尝试硬编码属性文件列表以包括该文件。 - Michael Wiles
1
@Michael Wiles,applicationContext-DEV-FNT.properties已被加载,但是该条目缺失。 - TechFind
你是否有多个可重复使用的配置文件,例如property-placeholder,如果需要解决问题,你需要添加属性ignore-unresolvable="true"。 - kfy0521
显示剩余3条评论
2个回答

3

看起来你的属性文件没有被加载。尝试使用以下方式显式地加载属性文件:

<property file="applicationContext-DEV-FNT.properties" />

1
问题可以通过传递“-DappRoot=ECM”参数和其他必需的参数来解决。

1
但这只是从命令行加载属性文件中的一个属性。那么applicationContext-DEV-FNT.properties文件中的其他属性呢? - bakoyaro

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接