gpt4 book ai didi

java - 处理队列的NoSuchMethodException

转载 作者:行者123 更新时间:2023-12-02 02:04:04 24 4
gpt4 key购买 nike

我尝试实现不同的队列来处理 Java 对象:

@SpringBootApplication
@ComponentScan("org.gateway.context")
public class ContextServer extends SpringBootServletInitializer {

protected static String QUEUE_DATABASE_API_ATTEMPT = "database-apiattempts-queue";
protected static final String EXCHANGE_DATABASE = "database";
protected static final String ROUTING_KEY_DATABASE_TRANSACTION = "database.event.transa";

protected CachingConnectionFactory connectionFactory;
protected RabbitTemplate databaseApiAttemptTemplate;
protected RabbitTemplate databaseEventLogsTemplate;

private static Class<ContextServer> applicationClass = ContextServer.class;

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
connectionFactory = new CachingConnectionFactory(HOST);
admin = new RabbitAdmin(connectionFactory);
.....

return application.sources(applicationClass);
}

@Bean
public SimpleMessageListenerContainer apiAttemptContainer(ConnectionFactory cf, ApiAttemptListener listener) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf);
container.setQueueNames(QUEUE_DATABASE_API_ATTEMPT);
container.setExclusive(true);
container.setConcurrentConsumers(1);
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
container.setMessageListener(new MessageListenerAdapter(listener, "apiattemptTransaction"));
container.setMessageConverter(new SerializerMessageConverter());
return container;
}

@Component
class ApiAttemptListener {

public ApiAttemptsBean apiattemptTransaction(ApiAttemptsBean ro) {
ApiAttemptsBean obj = new ApiAttemptsBean();
System.out.println("!!!! Performing ApiAttempts processing !!!!");
obj.setMerchant_id(454545);
return obj;
}
}

@Bean
public SimpleMessageListenerContainer eventLogsContainer(ConnectionFactory cf, EventLogstListener listener) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf);
container.setQueueNames(QUEUE_DATABASE_EVENT_LOGS);
container.setExclusive(true);
container.setConcurrentConsumers(1);
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
container.setMessageListener(new MessageListenerAdapter(listener, "eventLogsTransaction"));
container.setMessageConverter(new SerializerMessageConverter());
return container;
}

@Component
class EventLogstListener {

public EventLogsBean eventLogsTransaction(EventLogsBean ro) {
EventLogsBean obj = new EventLogsBean();
System.out.println("!!!! Performing EventLogs processing !!!!");
obj.setEntity_id(454545);
return obj;
}
}
}

但是当我部署代码时,我得到:

23:37:52,782 WARN  [org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler] (apiAttemptContainer-1) Execution of Rabbit message listener failed.: org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Failed to invoke target method 'apiattemptTransaction' with argument type = [class org.datalis.plugin.database.bean.TransactionsBean], value = [{org.datalis.plugin.database.bean.TransactionsBean@1fc52440}]
at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.NoSuchMethodException: org.datalis.database.context.ContextServer$ApiAttemptListener.apiattemptTransaction(org.datalis.plugin.database.bean.TransactionsBean)
... 12 more

23:37:52,782 WARN [org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler] (eventLogsContainer-1) Execution of Rabbit message listener failed.: org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Failed to invoke target method 'eventLogsTransaction' with argument type = [class org.datalis.plugin.database.bean.TransactionsBean], value = [{org.datalis.plugin.database.bean.TransactionsBean@52900dd1}]
Caused by: java.lang.NoSuchMethodException: org.datalis.database.context.ContextServer$EventLogstListener.eventLogsTransaction(org.datalis.plugin.database.bean.TransactionsBean)
at java.base/java.lang.Class.getMethod(Class.java:2067)

deployment.datalis_db.war//org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.invokeListenerMethod(MessageListenerAdapter.java:386) ... 12 更多

完整堆栈跟踪 https://pastebin.com/CCMidptq

我想我不能在方法名称中使用大写字母?您能建议可能是什么问题吗?

最佳答案

内部类必须是静态的才能成为 bean。否则它们依赖于外部类实例。使它们静态或将它们移出。

关于java - 处理队列的NoSuchMethodException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51071233/

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