gpt4 book ai didi

java - MongoDB 与 Spring 的复制

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

我在我的本地机器上用 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" />

最佳答案

好的,所以我找到了问题所在,只需要将 mongo-ref 添加到工厂即可。所以正确的配置是:

<mongo:mongo id="mongo" replica-set="host1:27017,host2:27017,host3:27017">
<mongo:db-factory dbname="my_db" mongo-ref="mongo" />

关于java - MongoDB 与 Spring 的复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20266518/

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