web-dev-qa-db-ja.com

org.Apache.camel.NoSuchBeanException:次のレジストリにBeanが見つかりませんでした:

次のルート定義があります。

@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}");

および次の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);
        }
    }

しかし、アプリケーションは起動しません。
痕跡:

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

私のコードベースの何が問題になっていますか?

更新:

Romat Vottnetのアドバイス 私は次のように書いています:

@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();
    }
}

しかし、私は見る:

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

アプリケーションの起動時。

チェックしました-@Beanとマークされたメソッドが呼び出されます。

4
gstackoverflow

これは機能します:

 from("seda:second")               
     .bean(HelloWorld.class, "smth")
4
gstackoverflow

「bean」にクラス名とメソッドを付ける方法が間違っています! beanを使用したい場合は、次の方法で作業できます。

from("direct:a").bean(ClassName.class , "methodName").to("direct:b");
from("direct:a").bean("registeredClassName","methodName").to("direct:b"); 
// this registered named is the name that you give to spring annotations like
//@Component , @Configuration , @Service , @Controller , @Bean etc...
// If you are using Camel stand alone then registeredClassName is the name that 
// you gave to  camel's registry. 
//For example:

SimpleRegistry simpleRegistry = new SimpleRegistry(); // this class is just a mapper
simpleRegistry.put("registeredClassName",new ClassName());

CamelContext camelContext = new DefaultCamelContext(simpleRegistry);
// In Spring Boot 
@Autowired 
private ClassName instanceOfClassName;
from("direct:a").bean(instanceOfClassName , "methodName").to("direct:b");

そして、これはあなたが経験した方法のようにクラスとメソッドを一緒に使用するための正しい方法です:

from("direct:a").to("bean:registeredClassName?method=methodName").to("direct:b");
// remember no parenthesis () for methodName 

from("direct:a").to("bean:FullyQualifiedClassName?method=Name").to("direct:b");

また、これはBeanとそのメソッドを呼び出す別の方法ですが、少し進歩しており、Simple-Languageとは何かを知る必要があります。

from("direct:start").bean("registeredClassName","methodName(${body},${header.customerId},${header.customerType}");

それで全部です :))

0
Od Chan

すでにSpringを使用しているので、Beanに@Componentアノテーションを付けて、ルート内で自動配線されたインスタンスを使用してみませんか?

0
cristianoms