【发布时间】:2018-08-24 05:47:40
【问题描述】:
我是 apache camel 的新手,刚刚开始。我有一个 spring boot (MVC) + mongodb 项目已经运行良好,当我尝试将它与 apache camel 集成时,我在控制台上遇到异常。根据我对异常 Spring Boot 的理解,当我在项目的其他任何地方使用 @ComponentScan(basePackages="packagePath") 时,我不能在骆驼路由文件上使用默认注释 @Component,因为它是 MVC 架构,所以我有控制器、服务& 我不能忽略的存储库,请帮我解决这个问题。
控制台异常
启动 ApplicationContext 时出错。显示条件报告 在启用“调试”的情况下重新运行您的应用程序。 2018-03-15 17:17:55.426 错误 744 --- [主] os.boot.SpringApplication
: 应用程序运行失败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个常用框架
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");
}
}
【问题讨论】:
-
这和骆驼无关。为什么要多次使用
@ComponentScan? -
你能建议我应该如何使用它吗?
-
编辑问题并提及您上面提到的所有类的包。
-
@pvpkiran 包添加到类中
-
将您的班级
ApplicationConfiguration放在com.era下,并从任何地方删除您的@ComponentScan并进行测试
标签: java mongodb spring-mvc spring-boot apache-camel