Failed to load ApplicationContext for报错解决方法
- 报错Failed to load ApplicationContext for
报错Failed to load ApplicationContext for
网上找了一堆方法都尝试了还是没用
包括添加mapperScan,添加配置类
配置pom文件
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-i7BRH8Lq-1690469332886)(https://imgblog.csdnimg.cn/bde8465f817146258107f2a6a4c4592b.png#pic_center)]
我觉得我的pom文件没有什么问题,结果问题也没出在pom文件上
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>demo</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
后面不断尝试最后发现问题出在yml配置文件上
server:
port: 80
spring:
datasource:
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/books
username: root
password: 123456
这是我的配置文件
乍一看好像什么问题都没有,确实没有什么问题,我照着黑马的课程做的
他们就这样写的,不过视频中没有出现什么问题,也没有报错,但我在本地一跑就报错
不断尝试之后我改了一下配置文件
这是黑马视频里的,我写的就和它一样,结果出问题了,我也不是很清除具体的原因
反正改了就没有报错,也许是版本的问题
修改后的配置文件
server:
port: 80
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/books
username: root
password: 123456
druid:
initial-size: 1
改了之后继续尝试运行,尽然没有报错
问题也就解决了,就很奇怪