gpt4 book ai didi

java - 没有可用的 'org.context.Databasetransactionlistener' 类型的合格 bean : expected at least 1 bean which qualifies as autowire candidate

转载 作者:行者123 更新时间:2023-11-30 06:07:08 25 4
gpt4 key购买 nike

我尝试使用此代码:

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

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

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
////
return application.sources(applicationClass);
}

@Bean
public SimpleMessageListenerContainer databaseTransactionContainer(ConnectionFactory cf,
Databasetransactionlistener listener) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf);
container.setQueueNames(QUEUE_DATABASE_TRANSACTION);
container.setExclusive(true);
container.setConcurrentConsumers(1);
container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
container.setMessageListener(new MessageListenerAdapter(listener, "databasetransaction"));
container.setMessageConverter(new SerializerMessageConverter());
return container;
}
}

@Component
class Databasetransactionlistener {

public TransactionsBean databasetransaction(TransactionsBean ro) {
TransactionsBean obj = new TransactionsBean();
System.out.println("!!!! Performing TransactionsBean processing !!!!");
obj.setTransaction_id(" ??? some_id: " + ro.getMerchant_id());
return obj;
}
}

但是当我部署代码时出现异常:没有 'org.database.context.Databasetransactionlistener' 类型的合格 bean 可用:预计至少有 1 个符合 Autowiring 候选资格的 bean。依赖注释:{}

完整日志:https://pastebin.com/L99iV9i9

你能建议我如何解决这个问题吗?也许我缺少一些配置?

最佳答案

您的 bean Databasetransactionlistener 尚未注册。扫描从上课开始就开始。

添加DependsOn SimpleMessageListenerContainer 确保您的类已首先注册。

顺便说一句,@SpringBootApplication 已经有 @ComponentScan

关于java - 没有可用的 'org.context.Databasetransactionlistener' 类型的合格 bean : expected at least 1 bean which qualifies as autowire candidate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51077256/

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