【问题标题】:Generic jpa repository with spring boot带有 Spring Boot 的通用 jpa 存储库
【发布时间】:2018-05-23 16:30:29
【问题描述】:

我正在尝试将通用 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 和 angular 前端)所以这是我的代码:

我的通用 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);
    }
}

【问题讨论】:

    标签: spring spring-boot spring-data spring-data-jpa


    【解决方案1】:

    @NoRepositoryBean 添加到您的JpaSpecificationRepository,这样您就可以排除此存储库的实例化。

    【讨论】:

      猜你喜欢
      • 2021-11-07
      • 1970-01-01
      • 2018-08-06
      • 2021-04-16
      • 2015-12-15
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 2016-03-26
      相关资源
      最近更新 更多