当我运行 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>

属性上下文.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

联合目标:
<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());
    }
}

最佳答案

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

关于spring - 无法解析占位符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6490461/

10-11 09:12