[英]Connection to multiple MongoDB DataBases Java
我有 2 個不同的數據庫(firstDB、secondDB),分別連接到它們每個都可以正常工作,但是如果在一個 session 我嘗試連接到第二個我得到一個錯誤,我連接到第一個沒有問題
public static MongoDatabase dbConnect() {
System.setProperty("javax.net.ssl.keyStore", "src/main/resources/firstDB.pkcs12");
System.setProperty("javax.net.ssl.keyStorePassword", "qwerty");
ConnectionString connectionString = new ConnectionString(System.getenv("FirstMongoDB_DEV"));
CodecRegistry pojoCodecRegistry = fromProviders(PojoCodecProvider.builder().automatic(true).build());
CodecRegistry codecRegistry = fromRegistries(MongoClientSettings.getDefaultCodecRegistry(),
pojoCodecRegistry);
MongoClientSettings clientSettings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.codecRegistry(codecRegistry)
.build();
return MongoClients.create(clientSettings).getDatabase("firstDB");
}
code to connect is similar for both, so if i'll call firstDB connect it work fine and if after that i call connect to secondDB i get com.mongodb.MongoSocketReadException: Prematurely reached end of stream If i swap the connections, first to the secondDB 然后到 firstDB,我會得到相同的結果
問題是 JVM 不知道如何動態更改 keyStore,幫助的庫
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.