Generic jpa repository with spring boot

2019-08-22 10:48发布

I'm trying to use generic Jpa Specification with spring boot but this problem was appeared.

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-05-23 18:18:27.340 ERROR 1048 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaSpecificationRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class java.lang.Object.

in my code I'm trying to use module concept, so I have 5 module (entities, dao, service, web and frontend with angular) so this is my code:

My generic Jpa Specification interface.

public interface JpaSpecificationRepository<T, ID extends Serializable>
        extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> {

}

Exemple of repository.

public interface HelloRepository extends JpaSpecificationRepository<Hello, Long> {

}

The service

@Service
public class HelloServiceImpl extends AbstractCRUDService<Hello, Long, HelloDto> {

    @Autowired
    protected HelloServiceImpl(HelloRepository repository, DozerBeanMapper mapper) {
        super(repository, mapper, Hello.class, HelloDto.class);
    }
}

and the controller

@RestController
@CrossOrigin("*")
@RequestMapping("/hello")
public class HelloController extends AbstractCRUDBackOfficeController<Long, HelloDto> {

    @Autowired
    HelloController(HelloServiceImpl service) {
        super(service);
    }
}

1条回答
疯言疯语
2楼-- · 2019-08-22 10:55

add @NoRepositoryBean to your JpaSpecificationRepository so you can exclude this Repository from being instantiated.

查看更多
登录 后发表回答