1 year ago

#327084

test-img

Arun Sudhakaran

Repository implementing just the JpaSpecificationExecutor causes error while starting Spring boot application

we were facing issues while starting our Spring Boot Application. We added a new API with a Controller, a Service class, and two Repository classes for two tables. This is the master table repository

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;    
import com.sixdee.wallet.core.domain.PromoTicketMaster;

@Repository
public interface PromoTicketMasterRepo extends JpaSpecificationExecutor<PromoTicketMaster> {

}

We had a look at this answer What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA? before creating this Repo as it was used for Pagination methods as well. It said that Because of the inheritance mentioned above, JpaRepository will have all the functions of CrudRepository and PagingAndSortingRepository . But the application didn't start with this Repo configuration and the console showed this error. The autowiring was fine.

*************************** APPLICATION FAILED TO START
***************************

Description:

Field promoTicketMasterRepo in com.sixdee.wallet.core.service.impl.PromoTicketServiceImpl required a bean of type 'com.sixdee.wallet.core.repository.PromoTicketMasterRepo' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.sixdee.wallet.core.repository.PromoTicketMasterRepo' in your configuration.

Then we changed the Repo like this and the application was started.

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.sixdee.wallet.core.domain.PromoTicketMaster;

@Repository
public interface PromoTicketMasterRepo extends JpaSpecificationExecutor<PromoTicketMaster>, CrudRepository<PromoTicketMaster, String> {

}

What was wrong with the first approach

java

spring-boot

jpa

repository

crud-repository

0 Answers

Your Answer

Accepted video resources