gpt4 book ai didi

Spring PropertyPlaceholderConfigurer 和 MongoDB 副本集

转载 作者:可可西里 更新时间:2023-11-01 10:07:30 24 4
gpt4 key购买 nike

在我的 spring 上下文中,我使用 PropertyPlaceholderConfigurer 从 env.properties 加载属性:

<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 和属性文件一起工作。

编辑此问题已针对 spring-data-mongodb:1.0.0.RELEASE 和 spring-data-mongodb:1.1.0.M1 修复

最佳答案

这实际上是最新的 Spring-data-mongo M5 里程碑中的一个错误。
http://forum.springsource.org/showthread.php?114672-Replica-set-configuration-problem

以下作品:

<mongo:mongo
replica-set="${mongo.replicaset.1}:${mongo.replicaset.1.port},${mongo.replicaset.2}:${mongo.replicaset.2.port},${mongo.replicaset.3}:${mongo.replicaset.3.port}">

关于Spring PropertyPlaceholderConfigurer 和 MongoDB 副本集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8159810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com