我正在將mongo java驅動程序jar升級到2.14.0。我的舊代碼工作正常,但下面的代碼顯示不贊成使用的類和構造函數,所以我需要兼容的代碼沒有棄用的類和構造函數爲mongo-java-driver.jar 2.14.0。mongo java驅動程序2.14.0。更改不推薦使用的代碼
public MongoTemplate getMongoTemplate() {
SimpleMongoDbFactory simpleMongoDbFactory = null;
try {
MongoOptions opts = new MongoOptions();//depricate
opts.threadsAllowedToBlockForConnectionMultiplier = getThreadsAllowedToBlockForConnectionMultiplier();//depricate
opts.connectionsPerHost = getConnectionsPerHost();//depricate
ServerAddress addr = new ServerAddress(getHost(), getPort());
Mongo mongo = new Mongo(addr, opts);//depricate
simpleMongoDbFactory = new SimpleMongoDbFactory(mongo,
getDatabaseName());//depricate
if (mongoTemplate == null) {
mongoTemplate = new MongoTemplate(simpleMongoDbFactory);
}
} catch (UnknownHostException e) {
LOGGER.error(e.getMessage());
} catch (MongoException e) {
LOGGER.error(e.getMessage());
}
return mongoTemplate;
}
你的問題是什麼呢? –
在那裏我提到過這些行要用spring-data-mongodb-1.9.2.jar的代碼替換。 –