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.
- Added
@EnableJpaRepositories
in springBoot application class. - Added
@Repostiories
to the repository interfaces. - extended the interfaces with
JpaRepository<Account, String>
- 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.
- you have added
spring-boot-starter-data-jpa
in your pom.xml - you have added the
entity
andrepo
package below one level of the application package. - 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!