com.heanbian.block.mongo.template.HMongoConfiguration Maven / Gradle / Ivy
package com.heanbian.block.mongo.template;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.core.SimpleReactiveMongoDatabaseFactory;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientURI;
@ComponentScan("com.heanbian.block.mongo.template")
@Configuration
public class HMongoConfiguration {
@Value("${spring.data.mongodb.uri:}")
private String uri;
@Value("${spring.data.mongodb.uri1:${spring.data.mongodb.uri}}")
private String uri1;
@Value("${spring.data.mongodb.uri2:${spring.data.mongodb.uri}}")
private String uri2;
@Value("${spring.data.mongodb.uri3:${spring.data.mongodb.uri}}")
private String uri3;
@Value("${spring.data.mongodb.uri4:${spring.data.mongodb.uri}}")
private String uri4;
@Bean(name = "mongoTemplate")
public MongoTemplate getMongoTemplate() {
return new MongoTemplate(new SimpleMongoDbFactory(new MongoClientURI(uri)));
}
@Bean(name = "mongoTemplate1")
public MongoTemplate getMongoTemplate1() {
return new MongoTemplate(new SimpleMongoDbFactory(new MongoClientURI(uri1)));
}
@Bean(name = "mongoTemplate2")
public MongoTemplate getMongoTemplate2() {
return new MongoTemplate(new SimpleMongoDbFactory(new MongoClientURI(uri2)));
}
@Bean(name = "mongoTemplate3")
public MongoTemplate getMongoTemplate3() {
return new MongoTemplate(new SimpleMongoDbFactory(new MongoClientURI(uri3)));
}
@Bean(name = "mongoTemplate4")
public MongoTemplate getMongoTemplate4() {
return new MongoTemplate(new SimpleMongoDbFactory(new MongoClientURI(uri4)));
}
@Bean(name = "reactiveMongoTemplate")
public ReactiveMongoTemplate getReactiveMongoTemplate() {
return new ReactiveMongoTemplate(new SimpleReactiveMongoDatabaseFactory(new ConnectionString(uri)));
}
@Bean(name = "reactiveMongoTemplate1")
public ReactiveMongoTemplate getReactiveMongoTemplate1() {
return new ReactiveMongoTemplate(new SimpleReactiveMongoDatabaseFactory(new ConnectionString(uri1)));
}
@Bean(name = "reactiveMongoTemplate2")
public ReactiveMongoTemplate getReactiveMongoTemplate2() {
return new ReactiveMongoTemplate(new SimpleReactiveMongoDatabaseFactory(new ConnectionString(uri2)));
}
@Bean(name = "reactiveMongoTemplate3")
public ReactiveMongoTemplate getReactiveMongoTemplate3() {
return new ReactiveMongoTemplate(new SimpleReactiveMongoDatabaseFactory(new ConnectionString(uri3)));
}
@Bean(name = "reactiveMongoTemplate4")
public ReactiveMongoTemplate getReactiveMongoTemplate4() {
return new ReactiveMongoTemplate(new SimpleReactiveMongoDatabaseFactory(new ConnectionString(uri4)));
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getUri1() {
return uri1;
}
public void setUri1(String uri1) {
this.uri1 = uri1;
}
public String getUri2() {
return uri2;
}
public void setUri2(String uri2) {
this.uri2 = uri2;
}
public String getUri3() {
return uri3;
}
public void setUri3(String uri3) {
this.uri3 = uri3;
}
public String getUri4() {
return uri4;
}
public void setUri4(String uri4) {
this.uri4 = uri4;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy