Bean parameter could not be found when migrating spring boot

Tomás Juárez :

I'm migrating services from spring boot 1.5 to spring boot 2.1 and I'm getting an error during this process. I have the following class for configuring my spring beans:

@Configuration
public class CompanyTransactionConfiguration {
    public CompanyTransactionConfiguration() {
    }

    @Bean
    public TransactionTaskRunner transactionTaskRunner(PlatformTransactionManager transactionManager) {
        return new TransactionTaskRunnerImpl(this.readWriteTransactionTemplate(transactionManager), this.readOnlyTransactionTemplate(transactionManager), this.newReadWriteTransactionTemplate(transactionManager));
    }
}

And, of course, a test class to check that everything work as expected:

@RunWith(SpringRunner.class)
public class ReferrerActivityRepositoryIT extends AbstractDomainIT {

    @Autowired
    private ReferrerActivityRepository referrerActivityRepository;

    @Autowired
    private TransactionTaskRunner transactionTaskRunner;

    ...
}

The issue is that this test was working fine after I changed my dependencies to a newer spring boot version (2.1), but now I'm getting the following error:

***************************
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.

I don't know what is going on, maybe I need to add another dependency because of changes in spring boot or change my application.properties file. The question is why is this happening? What should I change to get this working?

Thanks!

Lucas :

You didn't define PlatformTransactionManager bean. I assume you don't want to make it by yourself. You have to add spring.kafka.producer.transaction-id-prefix property to property file in order to use KafkaAutoConfiguration for PlatformTransactionManager.

  • 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

By the way your's CompanyTransactionConfiguration constructor is redundant as long as it doesn't have parameters. If there's no constructor in class compiler will create default one without parameters.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring Boot Bean could not be found

Spring Boot 2.1 EntityManagerFactory Bean could not be found

could not found bean for MongoRepository (Spring Boot)

Spring-boot:bean could not be found

Spring boot Field required a bean of type that could not be found

Spring Boot application failed to start, bean could not be found

Parameter 0 of constructor required a bean that could not be found

Spring boot javabean that could not be found

'Invalid bean definition' when migrating Spring Boot 2.0.6 to 2.1.0 with EvaluationContextExtensionSupport and custom PermissionEvaluator

Spring Boot: class with @Service bean bean not found

Spring - Error Parameter 0 of constructor in Service required a bean of type Configuration that could not be found

Parameter 0 of constructor in 'ItemController' required a bean of type '.ItemRepository' that could not be found. (Spring Data Cloud Firestore)

Unable to create a Configuration, because no Bean Validation provider could be found - Vaadin 14 Spring Boot

Spring boot basic application: field NotesRepository required a bean of type 'com.demo.NotesRepository' that could not be found

How to fix “Field … required a bean of type … that could not be found” exception Spring Boot

How to fix "Field ... required a bean of type ... that could not be found" exception Spring Boot

Spring-boot. A bean of type 'org.hibernate.SessionFactory' that could not be found

Spring boot 2.0.0.M4 required a bean named 'entityManagerFactory' that could not be found

Spring Boot controller required a bean of type 'org.dozer.Mapper' that could not be found

Spring AWS - required bean could not be found

Spring boot and Spring data no bean found entityMangerFactory

Spring Boot application-The bean could not be registered

Spring Boot application-The bean could not be registered

spring boot could not find bean of type

Spring Boot - Parameter of constructor required a single bean, but multiple were found for Generated ApiClient Constructor

Why is bean not found during Spring Boot?

Mapstruct + Lombok with Gradle in Spring Boot (Bean Not Found)

No Bean Found in Spring Boot application context

Spring Boot & MariaDB - Autowiring Problem - Bean not found