spring - 带有 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);
}
}
解决方案
添加@NoRepositoryBean
到您的JpaSpecificationRepository
,以便您可以从实例化中排除此存储库。
推荐阅读
- mysql - 无法使用 Angular 和 Sequelize 在 MariaDB sql server 中运行两个查询(语法错误)
- java - Java 8 Stream 将 Set 的 Object 内的 Object 转换为 Map
- matlab - 本地二进制模式功能
- robotframework - 如何在机器人框架中为我的关键字添加可选列表参数?
- akka - Akka-Cluster:间接连接的成员没有收到关于他自己的 UnreachableMember 事件
- javascript - 我的 . 在计算器。我只需要一个点
- r - 提取两个重复字符串之间的文本子字符串
- azure-virtual-machine - 如何连接到安装在 azure 上托管的虚拟机上的 mosquitto 代理?
- java - com.facebook.react.bridge.JavaJSExecutor$ProxyExecutorException
- graphite - 石墨没有显示正确的值