【发布时间】:2013-12-14 12:20:50
【问题描述】:
我在本地机器上用 MongoDB 配置了 Spring,没有复制,一切正常。 我也有一个工作正常的副本集。
现在我尝试添加副本集,但读取/写入仍然转到我的本地机器!
这是我的配置,host1-3是虚拟机:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
<mongo:repositories base-package="my.repositories" />
<mongo:mongo replica-set="host1:27017,host2:27017,host3:27017" />
<mongo:db-factory dbname="my_db" />
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
</bean>
有人有想法/建议吗?谢谢!
编辑: 好的,所以我发现了问题,只需要将 mongo-ref 添加到工厂。所以正确的配置是:
<mongo:mongo id="mongo" replica-set="host1:27017,host2:27017,host3:27017" />
<mongo:db-factory dbname="my_db" mongo-ref="mongo" />
【问题讨论】:
标签: java spring mongodb spring-mvc database-replication