gpt4 book ai didi

java - Camel 为存在且公开的方法抛出 MethodNotFound

转载 作者:太空宇宙 更新时间:2023-11-04 08:03:28 25 4
gpt4 key购买 nike

我正在测试 Camel 回合,但是当我有路线尝试访问 bean 中的特定方法时,它一直说没有找到这样的方法。来源:

public class CommunicatorTest
{
FakeMessageConverter converter;
CamelContext context;
ProducerTemplate template;
String producerEndpoint = "seda:messagesFound";
long test = 123456789;

static final Logger logger = Logger.getLogger(CommunicatorTest.class);

public CommunicatorTest()
{

}

@Before
public void setUp() throws Exception
{
converter = new FakeMessageConverter();
SimpleRegistry registry = new SimpleRegistry();
registry.put("converter", converter);
context = new DefaultCamelContext(registry);
template = context.createProducerTemplate();
context.addRoutes(new CommunicatorRoute());

logger.info("Done creating context");

context.start();
}

@After
public void tearDown() throws Exception
{
context.stop();
}


@Test
public void testExistanceOfBean()
{
Object lookup = context.getRegistry().lookup("converter");
assertTrue("Object not a MessageConverter", lookup instanceof FakeMessageConverter);
}

@Test
public void testRoute()
{
Message msg = new Message();
msg.setHeader(new MessageHeader());
msg.getHeader().setSourceId(test);

logger.info("Sending data");
template.sendBody(producerEndpoint, msg);


assertEquals("value not the same", test, converter.getSid());
logger.info("Done Sending");
}

private static class FakeMessageConverter
{

private long sid;
private boolean edited = false;

public FakeMessageConverter()
{
}

public void processMessage(Message msg)
{
sid = msg.getHeader().getSourceId();
edited = true;
logger.info("The sid"+sid);
}

/**
* @return the sid
*/
public long getSid()
{
return sid;
}

/**
* @param sid the sid to set
*/
public void setSid(long sid)
{
this.sid = sid;
}
}

}

路线如下:

public class CommunicatorRoute extends RouteBuilder
{

@Override
public void configure() throws Exception
{
from("seda:messagesFound").bean("converter", "processMessage");
}

}

异常情况如下:

ERROR [org.apache.camel.component.seda.SedaConsumer] - Error processing exchange. Exchange[Message: net.package.Message@f593af]. Caused by: [org.apache.camel.component.bean.MethodNotFoundException - Method with name: processMessage not found on bean: converter. Exchange[Message: net.package.message.Message@f593af]]

org.apache.camel.component.bean.MethodNotFoundException:在 bean:转换器上找不到名称为 processMessage 的方法。交换[消息:com.saic.jswe.common.cdif.message.Message@f593af]

我对 Camel 还很陌生,所以如果我犯了一些非常简单的错误,请告诉我。

最佳答案

你的类是私有(private)静态的。它必须是公共(public)静态的,以便 Camel 可以访问它。

关于java - Camel 为存在且公开的方法抛出 MethodNotFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12462833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com