spring data jpa 怎么使用泛型实现通用的dao类

open_yu open_yu 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近在学习springboot,遇到一个问题就是想自己写个通用的dao类,spring一直报错。
定义如下接口没有问题
public interface Itest0901 extends JpaRepository<test0901,Integer>

但是定义如下接口就出错了
public interface InterDao<T, ID extends Serializable> extends JpaRepository<T,ID>

错误信息:
2017-09-04 18:16:18.231  INFO 9976 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2017-09-04 18:16:18.851 WARN 9976 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'interDao': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class java.lang.Object


...全文

相关推荐

Hibernate泛型Dao

基于hibernate5 泛型Dao实例,下载后改一下数据库 配置直接可以用

hurmet

Spring-Data-JPA快速使用

《Spring-Data-JPA快速使用---我瞎写了》从核心实现和企业应用两个方面,由浅入深、由易到难地对Spring源码展开了系统的讲解,包括Spring的设计理念和整体架构、容器的基本实现、默认标签的解析、自定义标签的解析、bean的加载、容器的功能扩展、AOP、数据库连接JDBC、整合MyBatis、事务、SpringMVC、远程服务、Spring消息服务等内容。   《Spring源码深度解析》不仅介绍了使用Spring框架开发项目必须掌握的核心概念,还指导读者如何使用Spring框架编写企业级应用,并针对在编写代码的过程中如何优化代码、如何使得代码高效给出切实可行的建议,从而帮助读者全面提升实战能力。   《Spring源码深度解析》语言简洁,示例丰富,可帮助读者迅速掌握使用Spring进行开发所需的各种技能。《Spring源码深度解析》适合于已具有一定Java编程基础的读者,以及在Java平台下进行各类软件开发的开发人员、测试人员等。

呢喃北上

SSH泛型代码实例

3个泛型代码例子,都是从csdn别人的资源里下载的,免费分享,有普通泛型例子和SSH泛型例子

山与海666

SSH2全注解整合(spring2.5+hibernate3.3+struts2.1+泛型DAO+proxool连接池)

利用ssh(Spring2.5+Struts2.1+Hibernate3.3)全注解整合这3个流行的框架,实现了增、删、改、查的功能,目前功能还比较简单,以后功能再慢慢增加。欢迎大家下载并交流。

chend1982

SpringBoot_BaseDao.zip

尊重原创——SpringBoot_BaseDao.zip,内部含有反射,获取泛型类类型,如何使用等,自己下载查看

程序帝国
评论 5
收藏 已收藏
分享
返回顶部
open_yu
Java EE 67,535 成员 225,843 内容