记录若依分离版脚手架升级 springboot 3.X版本 中的报错 以及集成mybatis plus

问题一:

Web application could not be started as there was no org.springframework.boot.web.servlet.server.ServletWebServerFactory bean defined in the context.

移除父pom中的tomcat相关配置
在这里插入图片描述
子pom中增加 SpringBoot Web容器

      <!-- SpringBoot Web容器 -->
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

在这里插入图片描述

问题二:

Could not find artifact mysql:mysql-connector-java:pom:unknown 

在这里插入图片描述
新版mysql驱动包的写法发生了变化
原:

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

新:

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
        </dependency>

在这里插入图片描述

问题三:

dependencies,dependency.version' for javax.xml.bind:jaxb api:jar is missing.

在这里插入图片描述

jaxb-api 的版本号更改为新版,springboot3.X要求jdk17以上,jaxb-api的版本要适配jdk所以要变更
找个稳定版本进行变更
在这里插入图片描述在这里插入图片描述

问题四:

javax.servlet:javax.servlet api:jar:unknown was not found 

在这里插入图片描述
在springboot2.7之前 servlet 都是用的下面这依赖
在这里插入图片描述
但是新版springboot 用的如下依赖
在这里插入图片描述
在这里插入图片描述

<!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
<dependency>
    <groupId>jakarta.servlet</groupId>
    <artifactId>jakarta.servlet-api</artifactId>
    <version>6.1.0</version>
</dependency>

这里复制到pom中要把 <scope>provided</scope> 删掉 不然运行会有报错类导入不进来

引入之后将项目中所有 使用到 javax包下的 import 都更改为 jakarta下

问题五:

这个爆红是因为springboot升级了 但是 spring还没有

在这里插入图片描述
原版本:
在这里插入图片描述
所以将spring的版本进行升级到新版,在maven仓库查看新版进行更改
在这里插入图片描述

问题六:

SecurityConfig 中的爆红
在这里插入图片描述
security版本旧,需要更改新版本的
在这里插入图片描述
在这里插入图片描述
报错是因为新的方法名不叫这个
在这里插入图片描述

新的方法名叫 requestMatchers
在这里插入图片描述

问题七:

factoryBean0bjectType':java.lang.String

在这里插入图片描述
是因为mybatis版本过老的原因,需要更改,但是查找依赖发现他并没有mybatis依赖,他的依赖是从pagehelper.boot 中使用的
在这里插入图片描述
我这里的截图已经是处理之后的,所以看到mybatis 是灰色的
在这里插入图片描述
解决方案:使用新版的mybatis ,在父pom文件 和 common 的pom 文件中添加相关依赖
maven在使用时会优先使用此处的mybatis,会覆盖
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

问题八:

defining a bean of type 'com.alibaba.druid.spring.boot.autoconfigure.properties.Druidstatproperties' in

在这里插入图片描述
意思就是需要在我的配置文件中提供Druidstatproperties这个类

解决方案:
DruidConfig
添加注解 @EnableConfigurationProperties(DruidStatProperties.class)
在这里插入图片描述

问题九:

redis问题
在这里插入图片描述
配置文件中的redis 从 spring.redis 更改为 spring.data.redis
在这里插入图片描述
在这里插入图片描述

问题十:

No more pattern data allowed after {
    
    *...} or ** pattern element

在这里插入图片描述

在这里插入图片描述

这个问题是一个匹配规则的问题,
问题处理在 SecurityConfig 类中"/**/*.html", "/**/*.css", "/**/*.js"
在这里插入图片描述
这种写法是以前的写法,新版不允许这样写,新版需要将 /**/* 改为 /** 表达的意思是一样的

在这里插入图片描述

问题十一:

Name for argument of type [java.lang.String] not specified, and parameter name information not available via reflection. Ensure that the compiler uses the '-parameters' flag.

在这里插入图片描述
在这里插入图片描述
报错是因为编译工具的问题,需要我们自己加一个编译工具的插件
解决方案:
pom文件中添加 maven-compiler-plugin插件
在这里插入图片描述
在这里插入图片描述
复制到pom中标签改为 plugin 添加 configuration 刚才报错的 parameters 以及自己的jdk版本
在这里插入图片描述
问题就解决了,看到这里插件处 还可以优化下其他的 plugin 配置
war包这种配置我们也不使用,可以注释掉
在这里插入图片描述
spring-boot-maven-plugin 的版本也有点老,我们可以升级下
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

集成mybatis plus:

新的mybatis plus 是这个 spring-boot3 的这个
在这里插入图片描述
在这里插入图片描述
父pom文件中添加

在这里插入图片描述

common的 pom文件中添加
在这里插入图片描述
更改 framework.config.MyBatisConfig
在这里插入图片描述
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
更改为
MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
在此处发现 当前的依赖中并没有 MybatisSqlSessionFactoryBean ,于是将原依赖版本 3.5.10.1 调整为 3.5.10
在这里插入图片描述

在这里插入图片描述
然后进行启动
报错:


***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder.parse(MybatisMapperAnnotationBuilder.java:122)

The following method did not exist:

    'void org.apache.ibatis.session.Configuration.parsePendingMethods(boolean)'

The calling method's class, com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder, was loaded from the following location:

    jar:file:/G:/repository/com/baomidou/mybatis-plus-core/3.5.10/mybatis-plus-core-3.5.10.jar!/com/baomidou/mybatisplus/core/MybatisMapperAnnotationBuilder.class

The called method's class, org.apache.ibatis.session.Configuration, is available from the following locations:

    jar:file:/G:/repository/org/mybatis/mybatis/3.5.14/mybatis-3.5.14.jar!/org/apache/ibatis/session/Configuration.class

The called method's class hierarchy was loaded from the following locations:

    org.apache.ibatis.session.Configuration: file:/G:/repository/org/mybatis/mybatis/3.5.14/mybatis-3.5.14.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder and org.apache.ibatis.session.Configuration

在这里插入图片描述
原因呢就是 mybatis-boot中的 mybatis 版本与 mybatis plus 版本不兼容
在这里插入图片描述
解决方案:
在这里插入图片描述
根据AI反馈的版本对应关系 MyBatis-Plus 3.5.x‌:适用于MyBatis 3.5.x系列
查看我们 mybatis-spring-boot-startermybatis 的版本 发现其就是 3.5.14 ,按照这个版本对应来看是没有问题的
在这里插入图片描述
尝试在pom中引入 MyBatis 最新版本的依赖
在这里插入图片描述
启动成功了
在这里插入图片描述