带有 spring boot 的通用 jpa 存储库 [英] Generic jpa repository with spring boot

查看:33
本文介绍了带有 spring boot 的通用 jpa 存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 spring boot 中使用通用 Jpa 规范,但出现了这个问题.

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.

在我的代码中,我试图使用模块概念,所以我有 5 个模块(实体、dao、服务、web 和前端与 angular)所以这是我的代码:

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:

我的通用 Jpa 规范接口.

My generic Jpa Specification interface.

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

}

存储库示例.

public interface HelloRepository extends JpaSpecificationRepository<Hello, Long> {

}

服务

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

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

和控制器

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

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

推荐答案

@NoRepositoryBean 添加到您的 JpaSpecificationRepository 以便您可以从实例化中排除此 Repository.

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

这篇关于带有 spring boot 的通用 jpa 存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆