2011-06-27 89 views
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> 

env variable is:

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

您的$ {app.env}和$ {app.module}属性如何解决? – abalogh

+0

请发布Junit文件,我猜问题是propertyContext.xml没有加载。 – Ralph

+1

如何填充$ {app.env},$ {app.module}? – Ralph

回答

1

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

+1

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

3

看来,你的属性文件中,无法加载。尝试明确的加载属性文件中使用:

<property file="applicationContext-DEV-FNT.properties" /> 
相关问题