繁体   English   中英

NoSuchMethodException用于处理队列

[英]NoSuchMethodException for processing queue

我尝试实现用于处理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。 否则,它们将依赖于外部类实例。 使它们静止或移出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM