What is the best practise for Spring MongoDB configuration programmatically with moved credential and connection settings in a seprate .properties files?
I have configure it such a way but how to do it with .properties files, without any xml and probably better than my way:
App.class
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
MongoDBConfig.class
@Configuration
public class MongoDBConfig {
public @Bean
MongoDbFactory mongoDbFactory() throws Exception {
UserCredentials userCredentials = new UserCredentials("root", "qwerty");
return new SimpleMongoDbFactory(new MongoClient(), "test", userCredentials);
}
public @Bean MongoTemplate mongoTemplate() throws Exception {
return new MongoTemplate(mongoDbFactory());
}
Aucun commentaire:
Enregistrer un commentaire