【问题标题】:camel proxy complains about wrong type骆驼代理抱怨错误的类型
【发布时间】:2014-08-14 21:00:37
【问题描述】:

我配置了一个基于 Spring Boot 的应用程序以使用带有 activemq/jms 的远程处理。监听部分运行良好,但我在实现发送部分时遇到问题。

对于发件人,我回到“经典”骆驼和弹簧,因为我找到了更多的工作示例,但仍然收到错误:

org.springframework.beans.factory.BeanNotOfRequiredTypeException: 
Bean named 'myProxy' must be of type [foo.bar.YouNameIt], 
but was actually of type [com.sun.proxy.$Proxy83]

这是我尝试加载代理定义的方式:

ApplicationContext context = new ClassPathXmlApplicationContext("config/spring.xml");
YouNameIt youNameIt = context.getBean("myProxy", YouNameIt.class);

这是spring.xml中的条目:

<camel:proxy id="myProxy"
    serviceInterface="foo.bar.IYouNameIt"
    serviceUrl="activemq:queue:site12345" />

我做错了什么?

【问题讨论】:

  • 在你的 spring 配置中你为 IYouNameIt 创建代理,在代码示例中你使用 YouNameIt。其中一个是错的吗?还是那是你的问题?
  • 在所有示例中,我看到代理需要基于接口。我个人更喜欢没有界面的解决方案,但规范说我需要它。
  • 在您的代码中也使用该接口会更正确。您只能将代理转换为接口,因为代理正在实现该接口。

标签: java spring apache-camel activemq spring-boot


【解决方案1】:

访问接口IYouNameIt而不是实现类YouNameIt

IYouNameIt youNameIt = context.getBean("myProxy", IYouNameIt.class);

请参阅 here 了解完整的 Spring 远程处理示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-27
    • 2015-05-31
    • 2017-06-20
    • 1970-01-01
    • 2015-07-02
    相关资源
    最近更新 更多