在父类中修改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);
}