邯鄲wap網(wǎng)站建設(shè)報(bào)價(jià)網(wǎng)上宣傳方法有哪些
目錄
- 一、異常錯(cuò)誤
- 二、原因
- 三、解決方法
- 方法1. 將無法編譯的靜態(tài)資源放入可編譯目錄下
- 方法2. 重新編譯項(xiàng)目加載資源
- 方法3. 修改pom.xml資源配置文件
- 方法4. 不連接遠(yuǎn)程數(shù)據(jù)庫啟動(dòng),使用本地?cái)?shù)據(jù)庫
一、異常錯(cuò)誤
Springboot使用thymeleaf,并連接遠(yuǎn)程數(shù)據(jù)庫啟動(dòng)時(shí),無法加載resources中的靜態(tài)資源
瀏覽器報(bào)錯(cuò)
Failed to load resource: the server responded with a status of 404 ()
后端啟動(dòng)時(shí)報(bào)錯(cuò)
Servlet.service() for servlet [dispatcherServlet] in context with path [/ce] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template
前端打開頁面時(shí)后端報(bào)錯(cuò)
Exception processing template "/web/studyOutline/studyOutline": Error resolving template [/web/studyOutline/studyOutline], template might not exist or might not be accessible by any of the configured Template Resolvers
二、原因
打包編譯項(xiàng)目,顯示找不到j(luò)s、css、html等靜態(tài)資源,但本地路徑并沒有寫錯(cuò),于是我去找編譯文件,查看是不是靜態(tài)資源沒有編譯到,打開項(xiàng)目下的target文件夾
前往classes文件夾,發(fā)現(xiàn)項(xiàng)目resources下對(duì)應(yīng)的templates韋文件夾沒有編譯到,缺少靜態(tài)資源,當(dāng)然會(huì)報(bào)錯(cuò)了
三、解決方法
方法1. 將無法編譯的靜態(tài)資源放入可編譯目錄下
既然服務(wù)器不能編譯templates文件夾,那么把templates文件夾放入calsses路徑下即可,這樣處理就能獲取templats下的靜態(tài)資源了,但如果靜態(tài)資源有改動(dòng),需要手動(dòng)放入classes文件夾下,再次啟動(dòng)項(xiàng)目即可讀取資源
如果再次啟動(dòng)項(xiàng)目,還是顯示找不到j(luò)s、css、html等靜態(tài)資源,請(qǐng)看方法2
方法2. 重新編譯項(xiàng)目加載資源
由于服務(wù)器編譯攔截了靜態(tài)資源,導(dǎo)致出現(xiàn)異常,需要重新打包編譯
打開IDEA帶的Maven管理,雙擊clean清除由項(xiàng)目編譯創(chuàng)建的target
再雙擊install安裝jar包到本地倉庫
項(xiàng)目打包出現(xiàn)異常
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
系統(tǒng)默認(rèn)編碼是GBK,maven提升需要使用UTF-8,在setting中修改項(xiàng)目編碼為UTF-8
出現(xiàn) Failed to execute goal是由于測(cè)試用例有問題,
Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-test) on project springboot_04_profile: Input length = 1 -> [Help 1]
選擇跳過測(cè)試用例
再次雙擊install,編譯成功,啟動(dòng)項(xiàng)目即可讀取靜態(tài)資源
如果設(shè)置編碼還是打包失敗,或者顯示找不到j(luò)s、css、html等靜態(tài)資源,請(qǐng)看方法3
方法3. 修改pom.xml資源配置文件
如果設(shè)置編碼還是打包失敗,或者顯示找不到j(luò)s、css、html等靜態(tài)資源,說明服務(wù)器沒有訪問資源的權(quán)限,需要在pom.xml的build下引入資源文件
<!-- 引入靜態(tài)資源文件 --><resources><resource><directory>src/main/resources</directory><includes><include>**/*.css</include><include>**/*.js</include><include>**/*.html</include><include>**/*.png</include><include>**/*.properties</include><include>**/*.yml</include><include>**/*.xml</include><include>**/*.conf</include></includes></resource></resources>
再次insall,顯示打包成功,瀏覽器404的問題也解決了,加載了靜態(tài)資源
方法4. 不連接遠(yuǎn)程數(shù)據(jù)庫啟動(dòng),使用本地?cái)?shù)據(jù)庫
開頭說了,Springboot使用thymeleaf,并連接遠(yuǎn)程數(shù)據(jù)庫啟動(dòng)時(shí),無法加載resources中的靜態(tài)資源,這是一個(gè)大坑,如果不連接遠(yuǎn)程數(shù)據(jù)庫啟動(dòng),則不存在服務(wù)器訪問資源的問題
打開application.properties配置文件,注釋掉連接遠(yuǎn)程數(shù)據(jù)庫的代碼,改用本地?cái)?shù)據(jù)庫,就不會(huì)有訪問資源的問題了,可以直接加載,瀏覽器不再出現(xiàn)Failed to load resource問題
異常索引
- Failed to load resource: the server responded with a status of 404 ()
- Servlet.service() for servlet [dispatcherServlet] in context with path [/ce] threw exception [Request processing failed; nested
exception is org.thymeleaf.exceptions.TemplateInputException: Error
resolving template- Exception processing template “/web/studyOutline/studyOutline”: Error resolving template [/web/studyOutline/studyOutline], template
might not exist or might not be accessible by any of the configured
Template Resolvers- [INFO] Using ‘UTF-8’ encoding to copy filtered resources. [INFO] Using ‘UTF-8’ encoding to copy filtered properties files.
- Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources
(default-test) on project springboot_04_profile: Input length = 1 ->
[Help 1]