日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring boot: 构建项目时报错Not a managed type

發布時間:2025/6/17 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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也無法配置,明天繼續吧。

總結

以上是生活随笔為你收集整理的spring boot: 构建项目时报错Not a managed type的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。