我在本地机器上配置了Spring与MongoDB,没有复制,并且一切正常。 我也有一个副本集,工作正常。与Spring的MongoDB复制
现在我试图添加副本集,但读取/写入仍然会到我的本地机器!
这是我的配置,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" />
我知道,但主要不是我的本地机器,它是host1(VM)。 问题是读取和写入都转到本地主机而不是VM(这是我试图配置spring做的)。 – Ayelet