2011-11-16 105 views
2

在我的春天背景下,我使用PropertyPlaceholderConfigurer從env.properties加載性能:春PropertyPlaceholderConfigurer和MongoDB副本集

<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <list> 
       <value>classpath:env.properties</value> 
      </list> 
     </property> 
</bean> 

在我env.properties我有以下幾點:

db.mongo.replicationset=server1:1111, server2:2222, server3:3333 

最後,在Spring上下文:

<mongo:mongo id="mongo" replica-set="${db.mongo.replicationset}"> 
    <mongo:options slave-ok="true"/> 
</mongo:mongo> 

我看到的java.lang。 ArrayIndexOutOfBoundsException異常:

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed 
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [root-context.xml]; nested exception is java.lang.ArrayIndexOutOfBoundsException: 1 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) 
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124) 
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93) 
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) 
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397) 
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205) 
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704) 
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) 
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840) 
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) 
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463) 
    at org.apache.catalina.core.StandardService.start(StandardService.java:525) 
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754) 
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) 
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) 

一切正常用硬編碼複製設置如下:

<mongo:mongo id="mongo" replica-set="server1:1111, server2:2222, server3:3333"> 
    <mongo:options slave-ok="true"/> 
</mongo:mongo> 

我的猜測是,冒號或逗號可能是PropertyPlaceholderConfigurer特殊字符,所以不能使用。

我怎樣才能使這個配置與PropertyPlaceholderConfigurer和一個屬性文件一起工作。

編輯 這個問題是固定的彈簧數據的MongoDB:1.0.0.RELEASE和彈簧數據的MongoDB:1.1.0.M1

+0

正常,propertyplaceholderconfigurer應該通過這個字符串,因爲它是,所以我相信你的問題不在於此,我建議您重新檢查。 – ruhsuzbaykus

回答