簡體   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