Home > OS >  Spring boot Jpa is not working with Spring batch and spring integration
Spring boot Jpa is not working with Spring batch and spring integration

Time:12-06

I am working with spring batch. I needed to add some jpa repositories. So previously i was using JDBCTemplate which was working fine.

But when I started working with JPA, the spring boot application could not find the repos. Which were there.

@Autowired
ClassLevelConfigRepo clcr;

I checked these things as the best practices.

  1. Added @EnableJpaRepositories in springBoot application class.
  2. Added @Repostiories to the repository interfaces.
  3. extended the interfaces with JpaRepository<Account, String>
  4. Added @Entity to the entity classes and defined the @Table and @ Column annotations properly.

But I am still getting below error.

Field clcr in com.cloudtask.batchconfig.util.LhmUtility required a bean of type 'com.cloudtask.batchconfig.repo.ClassLevelConfigRepo' that could not be found.

I tried checking all the dependencies in pom.xml it was as per recommended. And I have all the tables defined properly in data base.

I was expecting the application to return the Autowired clcr object propely.

Edit 1 : spring boot application annotations

@SpringBootApplication
@ComponentScan({"com.cloudtask"})
@EnableAsync
@IntegrationComponentScan({"com.cloudtask"})
@EnableIntegrationManagement(defaultLoggingEnabled = "true")
@EnableJpaRepositories
@EntityScan
public class imclassApplication ```


CodePudding user response:

When you work with Spring Data Jpa with those basic points you should also keep track of below points.

  1. you have added spring-boot-starter-data-jpa in your pom.xml
  2. you have added the entity and repo package below one level of the application package.
  3. If you the package is at same level you should specify the exact package details in the annotation. in your case it should be like :
@EnableJpaRepositories("com.cloudtask.batchconfig.repo")
@EntityScan(basePackages = {"com.cloudtask.batchconfig.entity"})

Happy programming!

  • Related