有人尝试过在Spring-Boot中禁用mongodb的自动配置吗?
我正在使用spring-data-mongoDB试用spring-boot;使用基于java的配置;使用Spring-Boot1.2.1.Release,我导入了spring-boot-starter-html" target="_blank">web及其父pom来进行依赖关系管理。我还导入了spring-data-mongodb(也尝试了spring-boot-starter-mongodb)。
我需要连接到两个不同的MongoDB服务器。所以我需要为mongo connection,MongoTemplate等配置两组实例。我还想禁用自动配置。因为我连接到多个服务器,所以不需要自动配置一个默认的MongoTemplate和GridFsTemplate bean。
我的主类是这样的:
@Configuration
@EnableAutoConfiguration(exclude={MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@ComponentScan
//@SpringBootApplication // @Configuration @EnableAutoConfiguration @ComponentScan
public class MainRunner {
public static void main(String[] args) {
SpringApplication.run(MainRunner.class, args);
}
}
@Configuration
@EnableMongoRepositories(basePackageClasses = {Test1Repository.class},
mongoTemplateRef = "template1",
includeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = ".*Test1Repository")}
)
public class Mongo1Config {
@Bean
public Mongo mongo1() throws UnknownHostException {
return new Mongo("localhost", 27017);
}
@Primary
@Bean
public MongoDbFactory mongoDbFactory1() throws UnknownHostException {
return new SimpleMongoDbFactory(mongo1(), "test1");
}
@Primary
@Bean
public MongoTemplate template1() throws UnknownHostException {
return new MongoTemplate(mongoDbFactory1());
}
}
@Configuration
@EnableMongoRepositories(basePackageClasses = {Test2Repository.class},
mongoTemplateRef = "template2",
includeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = ".*Test2Repository")}
)
public class Mongo2Config {
@Bean
public Mongo mongo2() throws UnknownHostException {
return new Mongo("localhost", 27017);
}
@Bean
public MongoDbFactory mongoDbFactory2() throws UnknownHostException {
return new SimpleMongoDbFactory(mongo2(), "test2");
}
@Bean
public MongoTemplate template2() throws UnknownHostException {
return new MongoTemplate(mongoDbFactory2());
}
}
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:961)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:950)
at com.fourexpand.buzz.web.api.template.MainRunner.main(MainRunner.java:26)
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:98)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:75)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:378)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:155)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:157)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130)
... 7 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.core.io.ResourceLoader org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.resourceLoader; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gridFsTemplate' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.data.mongodb.MongoDbFactory]: : No qualifying bean of type [org.springframework.data.mongodb.MongoDbFactory] is defined: expected single matching bean but found 2: mongoDbFactory2,mongoDbFactory1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.data.mongodb.MongoDbFactory] is defined: expected single matching bean but found 2: mongoDbFactory2,mongoDbFactory1
我是这样做的:
@SpringBootApplication(exclude = {
MongoAutoConfiguration.class,
MongoDataAutoConfiguration.class
})
或者像丹·奥克建议的那样:
spring.autoconfigure.exclude= \
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration
在我的spring boot应用程序中,我配置了MQQueueConnectionFactory的两个不同实例(不同id),因为这是应用程序的需要。为此,我添加了ibm客户机JAR。 我还在代码中添加了spring jms依赖项,因为我需要JmsTemplate等类。添加此依赖项后,JmsAutoConfiguration在类路径中找到JmsTemplate并尝试配置bean。在这个过程中,它尝试
我正在用spring boot编写代码,它将csv作为输入,创建mongodb集合并将其插入mongodb。 目前,我坚持在基于spring boot的代码中使用mongodb。在MongoRepository接口上使用save方法时,我收到NullPointerException。 可能这个问题是由于不正确的配置在application.yml文件下面是mongodb特定的变化在applicat
我使用Spring中的@datajpatest进行测试,然后在内存数据库中使用H2 as,如下所述。我也在使用Flyway进行生产。然而,一旦测试开始,FLyway就会启动并读取SQL文件。如何排除FlywayAutoConfiguration并保留其余部分,如spring文档中所述,以便让Hibernate在H2中为我创建表?
我想使用最新版本的spring data mongodb,以便使用全文搜索功能,但我不知道如何使用spring boot starter data mongodb依赖项来指定这一点。 你可以在这里阅读:没有指定spring-data-mongodb版本的maven repository。 这是我的pom文件:
问题内容: 我正在创建应在Tomcat上运行的SOAP服务。 我正在为我的应用程序使用Spring Boot,类似于: 我的网络服务(示例): 问题: 每当我在webservice类中引发异常时,服务器上都会记录以下消息: ErrorPageFilter:由于响应已提交,因此无法转发到请求[/ services / MyWebservice]的错误页面。结果,响应可能具有错误的状态代码。如果您的应
Spring-Data-MongoDB。我如何使用spring-data-mongodb库在mongo中动态创建数据库? 我试图使用Spring-Mongodb-Data模块对Mongo数据库进行CRUD操作,通过示例和文章,我的假设是在定义MongoTemplate bean时应该在spring上下文xml中预定义databasename。 请帮帮我. 谢谢-RK