SpringBoot找不到映射文件的處理方式
SpringBoot找不到映射文件
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.qf.mapper.UserM
如果xml文件配置都確認(rèn)無誤還不能解決的話,可以嘗試在pom.xml文件中進(jìn)行如下配置:
<build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> </build>
后面我發(fā)現(xiàn)在yml文件里面,下面第一種寫法不行,第二種又可以。。。
mapper-locations: com/tt/mapper/*.xml
mapper-locations: com.tt.mapper/*.xml
SpringBoot映射本地文件到URL路徑
有兩種方法,使用配置類,或者在配置文件yml中配置
1、使用配置類
需要一個配置類,實(shí)現(xiàn)了WebMvcConfigurer接口
import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration // 1.添加配置文件注解 public class Config implements WebMvcConfigurer { // 2.實(shí)現(xiàn)WebMvcConfigurer接口 // ? ?@Value("${img.path}") ? ? private String locationPath = "F:\\img\\"; // 3.文件本地路徑 ? ? private static final String netPath = "/img/**"; // 映射路徑 ? ? // 目前發(fā)現(xiàn)如果本地路徑不是以分隔符結(jié)尾,在訪問時否需要把在最后一個文件夾名添加在映射路徑后面 ? ? // 如: ? ? // locationPath-->F:\img\ ? ?? ?訪問路徑-->ip:port/img/1.png ?? ?// locationPath-->F:\img ? ?? ??? ?訪問路徑-->ip:port/img/img/1.png ?? ?// locationPath-->F:\img\123\ ?? ?訪問路徑-->ip:port/img/1.png ?? ?// locationPath-->F:\img\123 ??? ?訪問路徑-->ip:port/img/123/1.png ?? ? ? ? @Override ? ? public void addResourceHandlers(ResourceHandlerRegistry registry) { ? ? ?? ?// 目前在本地Win系統(tǒng)測試需要在本地路徑前添加 "file:" ? ? ?? ?// 有待確認(rèn)Linux系統(tǒng)是否需要添加(已確認(rèn)) ? ? ?? ?// Linux系統(tǒng)也可以添加 "file:" ? ? ?? ?registry.addResourceHandler(netPath).addResourceLocations("file:"+locationPath); ? ? } }
2、在配置文件yml中配置
該方法沒有使用配置類的方法中,因本地路徑不是以分隔符結(jié)尾而造成的訪問問題
# 文件本地路徑 img: ? # ?path: /root/RandomImg/images/ ? ? #Linux ? path: F:\img\ ? ? ?#Win # 映射路徑 spring: ? resources: ? ? #訪問系統(tǒng)外部資源,將該目錄下的文件映射到系統(tǒng)下 ? ? static-locations: classpath:/static/, file:${img.path} #本地文件,多個路徑用英文逗號隔開 ? mvc: ? ? static-path-pattern: /img/** # 訪問路徑
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Logback 使用TurboFilter實(shí)現(xiàn)日志級別等內(nèi)容的動態(tài)修改操作
這篇文章主要介紹了Logback 使用TurboFilter實(shí)現(xiàn)日志級別等內(nèi)容的動態(tài)修改操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08java+jdbc+mysql+socket搭建局域網(wǎng)聊天室
這篇文章主要為大家詳細(xì)介紹了java+jdbc+mysql+socket搭建局域網(wǎng)聊天室,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-01-01SpringBoot解決@Component無法注入其他Bean的問題
這篇文章主要介紹了SpringBoot解決@Component無法注入其他Bean的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08@RefreshScope 自動刷新配置文件的實(shí)例講解
efreshScope(org.springframework.cloud.context.scope.refresh)是spring cloud提供的一種特殊的scope實(shí)現(xiàn),用來實(shí)現(xiàn)配置、實(shí)例熱加載,這篇文章主要介紹了@RefreshScope 自動刷新配置文件,需要的朋友可以參考下2022-11-11通過實(shí)例解析Spring Ioc項(xiàng)目實(shí)現(xiàn)過程
這篇文章主要介紹了Spring Ioc項(xiàng)目實(shí)踐過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-06-06Java實(shí)現(xiàn)畫圖 給圖片底部添加文字標(biāo)題
這篇文章主要介紹了Java實(shí)現(xiàn)畫圖 給圖片底部添加文字標(biāo)題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-11-11SpringBoot MDC全鏈路調(diào)用日志跟蹤實(shí)現(xiàn)詳解
這篇文章主要為大家介紹了SpringBoot MDC全鏈路調(diào)用日志跟蹤實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02