spring boot + apache camel + mongodb 集成问题 [英] spring boot + apache camel + mongodb integration issue
问题描述
我是 apache camel 的新手,刚刚开始.我有一个 spring boot (MVC) + mongodb 项目已经运行良好,当我尝试将它与 apache camel 集成时,我在控制台上遇到异常.根据我对异常 spring boot 的理解,我试图说当我使用 @ComponentScan(basePackages="packagePath")
@Component> 项目中的其他任何地方,因为它是 MVC 架构,所以我有 Controller、Service &我不能忽略的存储库,请帮我解决这个问题.
I am new to apache camel, just started. I have a spring boot (MVC) + mongodb project already running fine, when I am trying to integrate it with apache camel I am getting exception on console. As per my understanding on exception spring boot is trying to say that I cannot use default annotaion @Component
on camel Route file when I am using @ComponentScan(basePackages="packagePath")
anywhere else in the project, since it is a MVC architecture, I have Controller, Service & Repository which I cannot ignore, please help me solve this issue.
控制台异常
启动 ApplicationContext 时出错.显示条件报告在启用调试"的情况下重新运行您的应用程序.2018-03-15 17:17:55.426错误 744 --- [主要] o.s.boot.SpringApplication
: 应用程序运行失败
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-03-15 17:17:55.426 ERROR 744 --- [ main] o.s.boot.SpringApplication
: Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException:失败处理配置类的导入候选[com.era.conf.ApplicationConfiguration];嵌套异常是java.lang.IllegalStateException:无法评估条件org.apache.camel.spring.boot.health.HealthCheckRoutesAutoConfiguration由于 org/springframework/boot/bind/RelaxedPropertyResolver 不是成立.确保您自己的配置不依赖于该类.如果您是 @ComponentScanning springframework,也会发生这种情况包(例如,如果您通过以下方式将 @ComponentScan 放入默认包中错误)在org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:616)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] 在org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:548)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] 在org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:184)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] 在org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] 在org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] 在org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] 在org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:693)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] 在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] 在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] 在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388)[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:327)[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:1234)[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] 在com.era.conf.ApplicationConfiguration.main(ApplicationConfiguration.java:12)[classes/:na] 引起:java.lang.IllegalStateException:无法评估条件org.apache.camel.spring.boot.health.HealthCheckRoutesAutoConfiguration由于 org/springframework/boot/bind/RelaxedPropertyResolver 不是成立.确保您自己的配置不依赖于该类.如果您是 @ComponentScanning springframework,也会发生这种情况包(例如,如果您通过以下方式将 @ComponentScan 放入默认包中错误)在org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:55)~[spring-boot-autoconfigure-2.0.0.RELEASE.jar:2.0.0.RELEASE] 在org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:109)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] 在org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:217)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] 在org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:606)~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] ... 15个常用帧省略 引起:java.lang.NoClassDefFoundError:org/springframework/boot/bind/RelaxedPropertyResolver 在org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator.isEnabled(HierarchicalPropertiesEvaluator.java:49)~[camel-spring-boot-2.20.2.jar:2.20.2] 在org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator.evaluate(HierarchicalPropertiesEvaluator.java:42)~[camel-spring-boot-2.20.2.jar:2.20.2] 在org.apache.camel.spring.boot.util.GroupCondition.getMatchOutcome(GroupCondition.java:40)~[camel-spring-boot-2.20.2.jar:2.20.2] 在org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)~[spring-boot-autoconfigure-2.0.0.RELEASE.jar:2.0.0.RELEASE] ... 18常见的帧被省略 引起:java.lang.ClassNotFoundException:org.springframework.boot.bind.RelaxedPropertyResolver 在java.net.URLClassLoader.findClass(URLClassLoader.java:381)~[na:1.8.0_102] 在java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_102]在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)~[na:1.8.0_102] 在java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_102]...省略了22个常用帧
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.era.conf.ApplicationConfiguration]; nested exception is java.lang.IllegalStateException: Could not evaluate condition on org.apache.camel.spring.boot.health.HealthCheckRoutesAutoConfiguration due to org/springframework/boot/bind/RelaxedPropertyResolver not found. Make sure your own configuration does not rely on that class. This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake) at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:616) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:548) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:184) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:693) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] at com.era.conf.ApplicationConfiguration.main(ApplicationConfiguration.java:12) [classes/:na] Caused by: java.lang.IllegalStateException: Could not evaluate condition on org.apache.camel.spring.boot.health.HealthCheckRoutesAutoConfiguration due to org/springframework/boot/bind/RelaxedPropertyResolver not found. Make sure your own configuration does not rely on that class. This can also happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake) at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:55) ~[spring-boot-autoconfigure-2.0.0.RELEASE.jar:2.0.0.RELEASE] at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:109) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:217) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:606) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] ... 15 common frames omitted Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedPropertyResolver at org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator.isEnabled(HierarchicalPropertiesEvaluator.java:49) ~[camel-spring-boot-2.20.2.jar:2.20.2] at org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator.evaluate(HierarchicalPropertiesEvaluator.java:42) ~[camel-spring-boot-2.20.2.jar:2.20.2] at org.apache.camel.spring.boot.util.GroupCondition.getMatchOutcome(GroupCondition.java:40) ~[camel-spring-boot-2.20.2.jar:2.20.2] at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.0.0.RELEASE.jar:2.0.0.RELEASE] ... 18 common frames omitted Caused by: java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_102] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_102] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_102] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_102] ... 22 common frames omitted
POM
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.20.2</version>
</dependency>
</dependencies>
应用配置
package com.era.conf;
@SpringBootApplication
@ComponentScan(basePackages = "com.era.controller")
public class ApplicationConfiguration {
public static void main(String[] args) throws Exception {
SpringApplication.run(ApplicationConfiguration.class, args);
}
}
EmailResponseController
package com.era.controller;
@RestController
@RequestMapping("/emailResponse")
@ComponentScan(basePackages = "com.era.service")
public class EmailResponseController {
@Autowired private EmailResponseService serv;
@RequestMapping("/read")
public EmailResponseModel ExchangeServerEmailsReader() {
return serv.ExchangeServerEmailsReader();
}
}
服务
package com.era.service;
@Service
@EnableMongoRepositories("com.era.repository")
public class EmailResponseServiceImpl implements EmailResponseService {
@Autowired private EmailResponseRepository repo;
@Override
public EmailResponseModel ExchangeServerEmailsReader() {
final EmailResponseModel emailModel = new EmailResponseModel();
emailModel.setEmail(readEmailsFromExchangeServer());
return repo.save(emailModel);
}
}
CamelRouteClass
package com.era.route;
@Component
public class CamelRouteClass extends RouteBuilder {
@Override
public void configure() throws Exception {
from("file:C://response?noop=true").to("file:C://response2");
}
}
推荐答案
问题是 RelaxedPropertyResolver 已在最新版本的 spring-boot (2.0.0.RELEASE) 中删除.但是,最新的camel-spring-boot-starter 模块(编写本文时为2.20.2)仍然依赖于缺少的RelaxedPropertyResolver.
The problem is that RelaxedPropertyResolver has been removed in the latest release of spring-boot (2.0.0.RELEASE). However, the latest camel-spring-boot-starter module (2.20.2 when writing this) still depends on the missing RelaxedPropertyResolver.
要在 Camel 有新版本之前解决此问题,您需要将 spring-boot 降级到 1.5.10.RELEASE.
To solve the issue until there is a new version of Camel you need to downgrade spring-boot to 1.5.10.RELEASE.
这篇关于spring boot + apache camel + mongodb 集成问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!