spring boot: 构建项目时报错Not a managed type
今天在学习使用Spring Data JPA的时候,将bean和JpaRepository放在了不同的package中,导致无法构建项目,报以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/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/servlet/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 'readingListRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class bean.Book
异常是逐层抛出的,所以要定位到错误的地方,应该看最底下的内容,
java.lang.IllegalArgumentException: Not a managed type: class bean.Book
也就是我们没有按照SpringBoot的约定,默认扫描(application.java 入口类相对的兄弟包及其子包)
解决方法1:将bean和JpaRepository放在同一个package中。
解决方法2:在JpaRepository上添加注释,使得它能找到bean
@EntityScan("bean.Book")
这里整合以下常见的配置
@ComponentScan(basePackages = "com.boot.demo.xxx.*.*") 用于扫描@Controller @Service @EnableJpaRepositories(basePackages = "com.boot.demo.xxx.*.dao") 用于扫描Dao @Repository @EntityScan("com.boot.demo.xxx.*.*") 用于扫描JPA实体类 @Entity
好吧,现在完全不知道spring-boot的文件结构要如何,多创建了几个包,现在各种找不到类,controller也无法配置,明天继续吧。

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
go语言实现网易云音乐爬虫
前言 最近在学习go,学习一门语言最好的方式就是实践,之前学习python也是从爬虫入手,现在使用go语言写一个网易云音乐的爬虫,下面会简单介绍开发的过程,代码是初学者的水平,欢迎吐槽。 本项目github地址https://github.com/zhujiajunup/yunyinyue 开发工具 go1.11.2 windows/amd64 Google Chrome 71.0.3578.98 Fiddler v5.0.20182.28034 获取数据 不管用什么语言写爬虫,但步骤总是一致的,只是实现使用不应的语言而已,第一步当然是确认你想要什么,本次的目标是网易云音乐,我是想获取用户首页的听歌排行榜。 最先需要弄明白的是这些数据是怎么获取的,即云音乐是如何向服务器请求数据的,打开chrome的调试工具(F12),点到Network,搜索“钟无艳” 可以看到数据是https://music.163.com/weapi/v1/play/record?csrf_token=的POST请求来获取的,再看看该请求发送了什么数据 可以看到提交了一个表单,参数为params和encSecKey...
- 下一篇
编程语言运行过程
计算机的计算方式:二进制(0,1)所有都是;电脑是由:硬件+系统(组成的)。 操作系统:软件的服务平台,开发都是基于操作系统。抛弃系统(所有都要进行开发)很麻烦。 编程:就是将编程语言转换成(机器码)电脑只认识机器码,然后再由系统执行。编译:就是将代码转换成机器能看懂的语法。 c/c++: [代码] 编译【程序】(平台认识的可执行程序) 【计算机中运行】 运算速度 1秒 c#: [代码] 同上 java: [代码] 编译【中间代码】—————【虚拟机】(转换工作 中间码转成机器码)—————-计算机中运行 (1.3秒) python:[代码] —————————————【虚拟机】——-———计算机中运行 (6秒)时间是举例,说明。 三大操作系统;Windows 娱乐办公80% 服务器20% Unix(C语言) 20% 80% Linux(c++重写) 20% 80% 虚拟机翻译官 (根据平台不同 转成不同的机器码) 比C语言快的几秒是虚拟机在工作。 虚拟机:vm,java虚拟机jvm。 C语言:写源码;用文本文件写的(写出...
相关文章
文章评论
共有0条评论来说两句吧...