SpringBoot項(xiàng)目URL訪問(wèn)異常的問(wèn)題處理
SpringBoot項(xiàng)目URL訪問(wèn)異常
一,啟動(dòng)類與所在包的組件的位置,一定要在同一個(gè)包并行,不能直接在java下;
二,訪問(wèn)路徑問(wèn)題,要與Controller一致;
三,是不是項(xiàng)目本身的問(wèn)題呢,訪問(wèn)URL后
{
? ? "timestamp": "2023-06-16 13:13:21",
? ? "status": 500,
? ? "error": "Internal Server Error",
? ? "message": "Invalid bound statement (not found): com.atguigu.yygh.hosp.mapper.HospitalSetMapper.selectList",
? ? "path": "/admin/hosp/hospitalSet/findAll"
}問(wèn)題在于:
"Invalid bound statement (not found): com.atguigu.yygh.hosp.mapper.HospitalSetMapper.selectList",
原因:
依賴放在父模塊的pom.xml文件中,子模塊沒有繼承到父模塊的依賴
<dependency> ? ? <groupId>com.baomidou</groupId> ? ? <artifactId>mybatis-plus-boot-starter</artifactId> ? ? <version>最新版本</version> </dependency>
SpringBoot項(xiàng)目中數(shù)據(jù)庫(kù)的url 突然不能用
原因
我在啟動(dòng)springboot項(xiàng)目的時(shí)候,突然報(bào)了一個(gè)錯(cuò)誤
***************************
APPLICATION FAILED TO START
***************************Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
找了老半天,才發(fā)現(xiàn)bug所在,是因?yàn)槲以谥盀榱艘雑ava包下的mybatis的mapper.xml文件,在pom,xml中引用了一下的代碼
<build> ? ? ? ? <resources> ? ? ? ? ? ? <resource> ? ? ? ? ? ? ? ? <!-- java文件中一般會(huì)忽略,因?yàn)槲覀兊膞ml文件是放在java文件下 所以我們要將它忽略,也就是要打包--> ? ? ? ? ? ? ? ? <directory>src/main/java</directory> ? ? ? ? ? ? ? ? <includes> ? ? ? ? ? ? ? ? ? ? <include>**/*.xml</include> ? ? ? ? ? ? ? ? </includes> ? ? ? ? ? ? ? ? <filtering>false</filtering> ? ? ? ? ? ? </resource> ? ? ? ? </resources> ? ? </build>
所以說(shuō) 在resources文件夾下的yaml文件沒有能夠打包進(jìn)入
解決辦法
<build> ? ? ? ? <resources> ? ? ? ? ? ? <resource> ? ? ? ? ? ? ? ? <!-- java文件中一般會(huì)忽略,因?yàn)槲覀兊膞ml文件是放在java文件下 所以我們要將它忽略,也就是要打包--> ? ? ? ? ? ? ? ? <directory>src/main/java</directory> ? ? ? ? ? ? ? ? <includes> ? ? ? ? ? ? ? ? ? ? <include>**/*.xml</include> ? ? ? ? ? ? ? ? </includes> ? ? ? ? ? ? ? ? <filtering>false</filtering> ? ? ? ? ? ? </resource> ? ? ? ? ? ? <resource> ? ? ? ? ? ? ? ? <directory>src/main/resources</directory> ? ? ? ? ? ? ? ? <includes> ? ? ? ? ? ? ? ? ? ? <include>**/*.yaml</include> ? ? ? ? ? ? ? ? ? ? <include>**/*.properties</include> ? ? ? ? ? ? ? ? ? ? <include>**/*.xml</include> ? ? ? ? ? ? ? ? </includes> ? ? ? ? ? ? ? ? <filtering>false</filtering> ? ? ? ? ? ? </resource> ? ? ? ? </resources> ? ? </build>
這是我所遇到的問(wèn)題的答案,下面是一些其他的解決方案。
其他解決方案
排除數(shù)據(jù)源的自動(dòng)配置類
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})檢查配置文件中的信息是否填寫正確
?datasource: # mysql數(shù)據(jù)庫(kù)連接 ? ? ?type: com.zaxxer.hikari.HikariDataSource ? ? ?driver-class-name: com.mysql.cj.jdbc.Driver ? ? ?url: jdbc:mysql:///alibaba?serverTimezone=GMT%2B8&characterEncoding=utf-8 ? ? ?username: root ? ? ?password: root
剩下還有比如 符號(hào)轉(zhuǎn)義,在properties和yaml文件中是不需要符號(hào)轉(zhuǎn)義的,這也是它所強(qiáng)大的一點(diǎn)
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用@SpringBootTest注解進(jìn)行單元測(cè)試
這篇文章主要介紹了使用@SpringBootTest注解進(jìn)行單元測(cè)試,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09
java實(shí)現(xiàn)事件委托模式的實(shí)例詳解
這篇文章主要介紹了java實(shí)現(xiàn)事件委托模式的實(shí)例詳解的相關(guān)資料,這里提供實(shí)例來(lái)說(shuō)明如何實(shí)現(xiàn)改功能,希望能幫助到大家理解這樣的模式,需要的朋友可以參考下2017-08-08
Spring中獲取HttpServletRequest的三種方式小結(jié)
spring框架web環(huán)境中,獲取HttpServletRequest是常見的操作,本文將為大家詳細(xì)介紹一下Spring中獲取HttpServletRequest的三種方式,有需要的小伙伴可以了解下2026-04-04
基于SpringBoot服務(wù)端表單數(shù)據(jù)校驗(yàn)的實(shí)現(xiàn)方式
這篇文章主要介紹了基于SpringBoot服務(wù)端表單數(shù)據(jù)校驗(yàn)的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10
JavaWeb實(shí)現(xiàn)簡(jiǎn)單文件上傳功能
這篇文章主要為大家詳細(xì)介紹了JavaWeb實(shí)現(xiàn)簡(jiǎn)單文件上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06
Spring Boot 2.x基礎(chǔ)教程之配置元數(shù)據(jù)的應(yīng)用
這篇文章主要介紹了Spring Boot 2.x基礎(chǔ)教程之配置元數(shù)據(jù)的應(yīng)用,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01
JAVA通過(guò)Filter實(shí)現(xiàn)允許服務(wù)跨域請(qǐng)求的方法
這里的域指的是這樣的一個(gè)概念:我們認(rèn)為若協(xié)議 + 域名 + 端口號(hào)均相同,那么就是同域即我們常說(shuō)的瀏覽器請(qǐng)求的同源策略。這篇文章主要介紹了JAVA通過(guò)Filter實(shí)現(xiàn)允許服務(wù)跨域請(qǐng)求,需要的朋友可以參考下2018-11-11
Spring Cloud與分布式系統(tǒng)簡(jiǎn)析
這篇文章主要介紹了Spring Cloud與分布式系統(tǒng)的相關(guān)內(nèi)容,具有一定參考價(jià)值,需要的朋友可以了解下。2017-09-09

