无法解决占位符

时间:2011-06-27 08:47:54

标签: spring ant junit

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

env变量是:

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

2 个答案:

答案 0 :(得分:3)

您的属性文件似乎未加载。尝试使用以下方法显式加载属性文件:

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

答案 1 :(得分:1)

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