SpringBoot項(xiàng)目URL訪問異常的問題處理
SpringBoot項(xiàng)目URL訪問異常
一,啟動(dòng)類與所在包的組件的位置,一定要在同一個(gè)包并行,不能直接在java下;
二,訪問路徑問題,要與Controller一致;
三,是不是項(xiàng)目本身的問題呢,訪問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" }
問題在于:
"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ù)庫的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>
所以說 在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>
這是我所遇到的問題的答案,下面是一些其他的解決方案。
其他解決方案
排除數(shù)據(jù)源的自動(dòng)配置類
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
檢查配置文件中的信息是否填寫正確
?datasource: # mysql數(shù)據(jù)庫連接 ? ? ?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)文章
Java使用注解實(shí)現(xiàn)BigDecimal的四舍五入
BigDecimal是Java中的一個(gè)類,位于java.math包中,它提供了任意精度的有符號(hào)十進(jìn)制數(shù)字的表示,以及對這些數(shù)字進(jìn)行算術(shù)運(yùn)算的方法,本文介紹了Java使用注解實(shí)現(xiàn)BigDecimal的四舍五入的相關(guān)知識(shí),需要的朋友可以參考下2024-09-09基于JAVA的短信驗(yàn)證碼api調(diào)用代碼實(shí)例
這篇文章主要為大家詳細(xì)介紹了基于JAVA的短信驗(yàn)證碼api調(diào)用代碼實(shí)例,感興趣的小伙伴們可以參考一下2016-05-05SpringBoot自動(dòng)重啟、熱啟動(dòng)方式
這篇文章主要介紹了SpringBoot自動(dòng)重啟、熱啟動(dòng)方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03spring-boot.version2.6升級到2.7.18后security報(bào)錯(cuò)問題
這篇文章主要介紹了spring-boot.version2.6升級到2.7.18后security報(bào)錯(cuò)問題及解決,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08SpringMVC實(shí)現(xiàn)數(shù)據(jù)綁定及表單標(biāo)簽
這篇文章主要為大家詳細(xì)介紹了SpringMVC實(shí)現(xiàn)數(shù)據(jù)綁定及表單標(biāo)簽的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03