栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何配置两个实例mongodb使用spring引导和spring数据

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何配置两个实例mongodb使用spring引导和spring数据

我认为您可以使用Spring配置文件。

这是文档。

Spring Profiles提供了一种分离应用程序配置部分并使之仅在某些环境中可用的方法。

更新

注意: 我上面提到的文档中指示了我下面将要讨论的所有内容……您应该真正看一下本文档。这个文档很棒(不要开玩笑)。

从附录A.通用应用程序属性(Spring启动文档)

这是在中配置远程MongoDB实例的方法

application.properties

# MonGODB (MongoProperties)spring.data.mongodb.authentication-database= # Authentication database name.spring.data.mongodb.database=test # Database name.spring.data.mongodb.field-naming-strategy= # Fully qualified name of the FieldNamingStrategy to use.spring.data.mongodb.grid-fs-database= # GridFS database name.spring.data.mongodb.host=localhost # Mongo server host.spring.data.mongodb.password= # Login password of the mongo server.spring.data.mongodb.port=27017 # Mongo server port.spring.data.mongodb.repositories.enabled=true # Enable Mongo repositories.spring.data.mongodb.uri=mongodb://localhost/test # Mongo database URI. When set, host and port are ignored.spring.data.mongodb.username= # Login user of the mongo server.

这是在中配置嵌入式MongoDB实例的方法

application.properties

# EMBEDDED MonGODB (EmbeddedMongoProperties)spring.mongodb.embedded.features=SYNC_DELAY # Comma-separated list of features to enable.spring.mongodb.embedded.storage.databaseDir= # Directory used for data storage.spring.mongodb.embedded.storage.oplogSize= # Maximum size of the oplog in megabytes.spring.mongodb.embedded.storage.replSetName= # Name of the replica set.spring.mongodb.embedded.version=2.6.10 # Version of Mongo to use.

从更改配置取决于环境(spring启动文件)

要对属性文件执行相同的操作,可以使用

application-${profile}.properties
指定特定于配置文件的值。

您可以将MongoDB嵌入式配置定义为

application-dev.properties
,将MongoDB远程配置定义为
application-prod.properties

更新二:回归

我假设您在(从document)类中启动嵌入式MongoDB实例:

import de.flapdoodle.embed.mongo.config.ArtifactStoreBuilder;    ...    MongodStarter starter = MongodStarter.getDefaultInstance();    String bindIp = "localhost";    int port = 12345;    IMongodConfig mongodConfig = new MongodConfigBuilder()        .version(Version.Main.PRODUCTION)        .net(new Net(bindIp, port, Network.localhostIsIPv6()))        .build();    MongodExecutable mongodExecutable = null;

您可以为此类分配spring概要文件,例如(来自document):

@Configuration@Profile("dev")public class ProductionConfiguration {    // ...}

这样,仅当您选择

dev
概要文件时,才会启动嵌入式MongoDB 。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/412114.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号