文章目录
- 1. 无效的源发行版: 17
 - 2. java: 无法访问org.springframework.boot.SpringApplication
 - 3. java: 程序包org.junit.jupiter.api不存在
 - 4. @SpringbootTest注解爆红
 - 5. maven命令安装本地jar包报错:[拒绝访问]
 - 5. maven命令安装本地jar包报错:Unknown lifecycle phase “.bi...0.hxtxavjy“. You must specify...
 - 6. has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
 - 7. maven 编译项目报错:无效的标记 --release
 - 8. 新建启动类爆红
 - 9. springbootlianjieredis报错:nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
 - 10. springboot启动访问controller报错404
 
1. 无效的源发行版: 17
原因:项目构建时没有统一好各类构建版本。
解决:【IDEA报错】java错误: 无效的源发行版: 17 处理办法(亲测有效)
2. java: 无法访问org.springframework.boot.SpringApplication

原因:IDEA默认的springboot-starter-parent版本是3.0,而我的项目springboot-starter版本是3.1.1.,autoConfigure也是3.1.1.所以降低版本就好了~
 
 
3. java: 程序包org.junit.jupiter.api不存在
缺少测试用的jar包了,导入依赖即可。
 
4. @SpringbootTest注解爆红
在pom.xml添加依赖。
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
</dependency>
 
5. maven命令安装本地jar包报错:[拒绝访问]
原因:打包命令里,-Dfile除了需要本地jar包的路径还要包含jar包本身名称!!!
 如:
-Dfile=D:\JAVA\
Projects\Demo\out\artifacts\demoStarter_jar\demoStarter.jar
 
5. maven命令安装本地jar包报错:Unknown lifecycle phase “.bi…0.hxtxavjy“. You must specify…
原因:打包命令里参数 -DgroupId 和 -Dversion 对应的值都要加 双引号,不然识别不了就会报此错。
 如:
mvn install:install-file -DgroupId="com.example" -DartifactId=service-starter -Dversion="1.0" -Dpackaging=jar -Dfile=D:\JAVA\
Projects\Demo\out\artifacts\demoStarter_jar\demoStarter.jar
 
解决:这里
6. has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
这是java编译器版本编译出来的java类文件在当前低版本下编译器使用时报错。仔细检查我的项目,在单元测试类中引用了高版本的依赖包导致此错误。
 另外, 项目编译注意尽量都统一版本号。
 参考这里:编译器与类文件版本对应
7. maven 编译项目报错:无效的标记 --release
如图:
 
 检查步骤:
 ① 是不是pom.xml文件里写了maven插件的release,要去掉,jdk9以后才支持maven -release
 ② 看是不是springboot版本、jdk版本 、maven不匹配了
8. 新建启动类爆红

 原因:启动类要在一个包目录下才可以被识别到,新建一个com.example包,将启动类拖到下面,即可运行。
9. springbootlianjieredis报错:nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
报错:
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'redisConnectionFactory' defined in class path resource 
[org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.class]: Bean instantiation via factory method failed; 
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory]: 
Factory method 'redisConnectionFactory' threw exception; 
nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
 
解决:
 添加连接池依赖 commons-pool2 即可。
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
</dependency>
 
10. springboot启动访问controller报错404

 原因: controller类写在了main主类的上一个目录。默认扫描同级及下级目录的springboot当然找不到咯。
 



















