项目依赖升级spring boot2.2.x->2.6.5

在父类中修改spring boot的版本

<dependency
	<groupId>org.springframework.boot</groupId
	<artifactId>spring-boot-dependencies</artifactId
	<version>2.6.5</version
	<type>pom</type
	<scope>import</scope
</dependency>

项目启动报错

问题一

There is no DataSource named ‘null’

定时任务问题
这是由于SpringBoot在2.5.6版本之后就删除了关于Quartz相关的以来。所以在2.5.6版及之前还是可以用的。

解决
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX

改为

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX

全局搜索自己项目中有没有这个配置

prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore");

问题二

配置好之后可能会出现循环依赖问题

在这里插入图片描述
bug大概意思是:不鼓励依赖循环引用,默认情况下是禁止的。更新您的应用程序以删除 bean 之间的依赖循环。作为最后的手段,可以通过将 spring.main.allow-circular-references 设置为 true 来自动中断循环。

解决

SpringBoot2.6 正式发布:循环依赖默认禁止。如上提供解决方案为将spring.main.allow-circular-references 设置为 true,来自动中断循环。

如果是.properties文件,在文件中添加

spring.main.allow-circular-references=true

如果是.yml文件,则在文件中添加

spring:
  main:
    allow-circular-references: true

问题三

Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException

我项目中出现这个问题的原因是spring boot版本和swagger版本不兼容问题

解决

swagger用到的jar包

        <!-- swagger2-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
        </dependency>

        <!--防止进入swagger页面报类型转换错误,排除2.9.2中的引用,手动增加1.5.21版本-->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>1.5.21</version>
        </dependency>

        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
            <version>1.5.21</version>
        </dependency>

application.yml 或applicaiton.properties 中添加如下配置

spring
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

问题四

When allowCredentials is true, allowedOrigins cannot contain the specia
前端页面无法登录,需要修改跨域配置

解决
	@Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        // 设置访问源地址
        config.addAllowedOrigin("*");
        // 设置访问源请求头
        config.addAllowedHeader("*");
        // 设置访问源请求方法
        config.addAllowedMethod("*");
        // 对接口配置跨域设置
        source.registerCorsConfiguration("/**", config);
        return new CorsFilter(source);
    }

改为

	@Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        // 设置访问源地址
        config.addAllowedOriginPattern("*");
        // 设置访问源请求头
        config.addAllowedHeader("*");
        // 设置访问源请求方法
        config.addAllowedMethod("*");
        // 对接口配置跨域设置
        source.registerCorsConfiguration("/**", config);
        return new CorsFilter(source);
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值