首页 > 解决方案 > 带有 Spring Boot 的通用 jpa 存储库

问题描述

我正在尝试将通用 Jpa 规范与 spring boot 一起使用,但出现了这个问题。

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 和带角度的前端)所以这是我的代码:

我的通用 Jpa 规范接口。

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);
    }
}

标签: springspring-bootspring-dataspring-data-jpa

解决方案


添加@NoRepositoryBean到您的JpaSpecificationRepository,以便您可以从实例化中排除此存储库。


推荐阅读