为了账号安全,请及时绑定邮箱和手机立即绑定

迁移弹簧引导时找不到 Bean 参数

迁移弹簧引导时找不到 Bean 参数

交互式爱情 2022-08-03 10:16:03
我正在将服务从 spring boot 1.5 迁移到 spring boot 2.1,但在此过程中出现错误。我有以下用于配置我的弹簧豆的类:@Configurationpublic class CompanyTransactionConfiguration {    public CompanyTransactionConfiguration() {    }    @Bean    public TransactionTaskRunner transactionTaskRunner(PlatformTransactionManager transactionManager) {        return new TransactionTaskRunnerImpl(this.readWriteTransactionTemplate(transactionManager), this.readOnlyTransactionTemplate(transactionManager), this.newReadWriteTransactionTemplate(transactionManager));    }}当然,还有一个测试类来检查一切是否按预期工作:@RunWith(SpringRunner.class)public class ReferrerActivityRepositoryIT extends AbstractDomainIT {    @Autowired    private ReferrerActivityRepository referrerActivityRepository;    @Autowired    private TransactionTaskRunner transactionTaskRunner;    ...}问题是,在我将依赖项更改为较新的spring boot版本(2.1)后,此测试工作正常,但现在我收到以下错误:***************************APPLICATION FAILED TO START***************************Description:Parameter 0 of method transactionTaskRunner in com.company.core.server.config.CompanyTransactionConfiguration required a bean of type 'org.springframework.transaction.PlatformTransactionManager' that could not be found.The following candidates were found but could not be injected:    - Bean method 'transactionManager' in 'DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration' not loaded because @ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans    - Bean method 'kafkaTransactionManager' in 'KafkaAutoConfiguration' not loaded because @ConditionalOnProperty (spring.kafka.producer.transaction-id-prefix) did not find property 'spring.kafka.producer.transaction-id-prefix' ...Action:Consider revisiting the entries above or defining a bean of type 'org.springframework.transaction.PlatformTransactionManager' in your configuration.我不知道发生了什么,也许我需要添加另一个依赖项,因为Spring boot中的更改或更改了我的文件。问题是为什么会发生这种情况?我应该更改哪些内容才能使其正常工作?application.properties谢谢!
查看完整描述

1 回答

?
精慕HU

TA贡献1845条经验 获得超8个赞

你没有定义豆子。我假设你不想自己做。您必须将属性添加到属性文件才能使用KafkaAutoConfiguration for PlatformTransactionManager。PlatformTransactionManagerspring.kafka.producer.transaction-id-prefix

  • Bean 方法 'kafkaTransactionManager' 在 'KafkaAutoConfiguration' 中未加载,因为 @ConditionalOnProperty (spring.kafka.producer.transaction-id-prefix) 未找到属性 spring.kafka.producer.transaction-id-prefix

顺便说一句,您的公司事务配置构造函数是冗余的,只要它没有参数。如果类中没有构造函数,编译器将创建一个没有参数的默认构造函数。


查看完整回答
反对 回复 2022-08-03
  • 1 回答
  • 0 关注
  • 212 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号