SpringBoot項目URL訪問異常的問題處理
SpringBoot項目URL訪問異常
一,啟動類與所在包的組件的位置,一定要在同一個包并行,不能直接在java下;
二,訪問路徑問題,要與Controller一致;
三,是不是項目本身的問題呢,訪問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項目中數(shù)據(jù)庫的url 突然不能用
原因
我在啟動springboot項目的時候,突然報了一個錯誤
***************************
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所在,是因為我在之前為了引入java包下的mybatis的mapper.xml文件,在pom,xml中引用了一下的代碼
<build> ? ? ? ? <resources> ? ? ? ? ? ? <resource> ? ? ? ? ? ? ? ? <!-- java文件中一般會忽略,因為我們的xml文件是放在java文件下 所以我們要將它忽略,也就是要打包--> ? ? ? ? ? ? ? ? <directory>src/main/java</directory> ? ? ? ? ? ? ? ? <includes> ? ? ? ? ? ? ? ? ? ? <include>**/*.xml</include> ? ? ? ? ? ? ? ? </includes> ? ? ? ? ? ? ? ? <filtering>false</filtering> ? ? ? ? ? ? </resource> ? ? ? ? </resources> ? ? </build>
所以說 在resources文件夾下的yaml文件沒有能夠打包進入
解決辦法
<build> ? ? ? ? <resources> ? ? ? ? ? ? <resource> ? ? ? ? ? ? ? ? <!-- java文件中一般會忽略,因為我們的xml文件是放在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ù)源的自動配置類
@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
剩下還有比如 符號轉(zhuǎn)義,在properties和yaml文件中是不需要符號轉(zhuǎn)義的,這也是它所強大的一點
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Spring中獲取HttpServletRequest的三種方式小結(jié)
spring框架web環(huán)境中,獲取HttpServletRequest是常見的操作,本文將為大家詳細介紹一下Spring中獲取HttpServletRequest的三種方式,有需要的小伙伴可以了解下2026-04-04
基于SpringBoot服務端表單數(shù)據(jù)校驗的實現(xiàn)方式
這篇文章主要介紹了基于SpringBoot服務端表單數(shù)據(jù)校驗的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10
Spring Boot 2.x基礎(chǔ)教程之配置元數(shù)據(jù)的應用
這篇文章主要介紹了Spring Boot 2.x基礎(chǔ)教程之配置元數(shù)據(jù)的應用,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-01-01
JAVA通過Filter實現(xiàn)允許服務跨域請求的方法
這里的域指的是這樣的一個概念:我們認為若協(xié)議 + 域名 + 端口號均相同,那么就是同域即我們常說的瀏覽器請求的同源策略。這篇文章主要介紹了JAVA通過Filter實現(xiàn)允許服務跨域請求,需要的朋友可以參考下2018-11-11

