通过JAVA应用程序与MongoDB连接时,添加带有密码短语的根CA文件和客户端证书

时间:2018-07-02 08:18:13

标签: java mongodb spring-boot spring-data-mongodb mongodb-java

我必须以编程方式连接到使用SSL保护的远程数据库。 Connection Properties in Studio 3T

与数据库连接时,如何在Java中将这些证书和密码一起添加

示例代码-

@Configuration
@PropertySource("classpath:DBConfig.properties")
public class SpringMongoConfig extends AbstractMongoConfiguration {

    final static Logger logger = LogManager.getLogger(SpringMongoConfig.class);
    @Autowired
    Environment environment;

    @Override
    @Bean(name = "mongo-db-name")
    public String getDatabaseName() {
        return this.mongoClientURI().getDatabase();
    }

    @Override
    @Bean
    public MongoClient mongoClient() {
        logger.info("IMP!! Creating instance of MongoClient");
        return new MongoClient(this.mongoClientURI());
    }

    private MongoClientURI mongoClientURI() {
        return new MongoClientURI(environment.getProperty("mongodb.url"));
        //But unable to add the certificates needed to connect
    }
}

0 个答案:

没有答案