I have the following route definition:
@Component
public class CamelRoutes extends RouteBuilder {
@Override
public void configure() throws Exception {
from("seda:second")
.bean("helloWorld?method=smth")
.process(exchange -> {
System.out.println("Message:" + exchange.getIn().getBody());
})
.log("body:${body}");
and following bean:
public static class HelloWorld {
public void execute(String str){
System.out.println("HelloWorld#execute: " + str);
}
public void smth(String str){
System.out.println("HelloWorld#smth: " + str);
}
}
But application doesn't start.
trace:
org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route4 at: >>> Bean[ref:helloWorld?method=smth] <<< in route: Route(route4)[[From[seda:second]] -> [Bean[ref:helloWorld?me... because of No bean could be found in the registry for: helloWorld?method=smth
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1831) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:136) ~[camel-spring-2.20.0.jar:2.20.0]
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:174) ~[camel-spring-2.20.0.jar:2.20.0]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at SpringBootCamelIntegrationApplication.main(SpringBootCamelIntegrationApplication.java:9) [classes/:na]
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route4 at: >>> Bean[ref:helloWorld?method=smth] <<< in route: Route(route4)[[From[seda:second]] -> [Bean[ref:helloWorld?me... because of No bean could be found in the registry for: helloWorld?method=smth
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1298) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1135) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3714) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3428) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:208) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3236) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3232) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3255) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3232) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3155) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:133) ~[camel-spring-2.20.0.jar:2.20.0]
... 15 common frames omitted
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: helloWorld?method=smth
at org.apache.camel.component.bean.RegistryBean.getBean(RegistryBean.java:94) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.component.bean.RegistryBean.createCacheHolder(RegistryBean.java:69) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:251) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:549) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:510) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:226) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1295) ~[camel-core-2.20.0.jar:2.20.0]
... 27 common frames omitted
What wrong with my code base ?
According Romat Vottnet advice I've wrote following:
@Component
public class CamelRoutes extends RouteBuilder {
@Override
public void configure() throws Exception {
from("seda:second")
.bean("helloWorld?method=smth()");
}
public static class HelloWorld {
public void execute(String str) {
System.out.println("HelloWorld#execute: " + str);
}
public void smth(String str) {
System.out.println("HelloWorld#smth: " + str);
}
}
@Bean(name = "helloWorld")
public HelloWorld helloWorld() {
return new HelloWorld();
}
}
But I see:
org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route4 at: >>> Bean[ref:helloWorld?method=smth()] <<< in route: Route(route4)[[From[seda:second]] -> [Bean[ref:helloWorld?me... because of No bean could be found in the registry for: helloWorld?method=smth()
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1831) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:136) ~[camel-spring-2.20.0.jar:2.20.0]
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:174) ~[camel-spring-2.20.0.jar:2.20.0]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at SpringBootCamelIntegrationApplication.main(SpringBootCamelIntegrationApplication.java:9) [classes/:na]
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route4 at: >>> Bean[ref:helloWorld?method=smth()] <<< in route: Route(route4)[[From[seda:second]] -> [Bean[ref:helloWorld?me... because of No bean could be found in the registry for: helloWorld?method=smth()
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1298) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1135) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3714) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3428) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:208) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3236) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3232) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3255) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3232) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3155) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:133) ~[camel-spring-2.20.0.jar:2.20.0]
... 15 common frames omitted
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: helloWorld?method=smth()
at org.apache.camel.component.bean.RegistryBean.getBean(RegistryBean.java:94) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.component.bean.RegistryBean.createCacheHolder(RegistryBean.java:69) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:251) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:549) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:510) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:226) ~[camel-core-2.20.0.jar:2.20.0]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1295) ~[camel-core-2.20.0.jar:2.20.0]
... 27 common frames omitted
when application starts.
I checked - method marked as @Bean
is invoked.
this works:
from("seda:second")
.bean(HelloWorld.class, "smth")