该问题已解决!特此记录!欢迎指点分享!
目录
(1)继承 mvc的配置类 WebMvcConfigurationSupport
公司 Springboot1.5 - 升级 Springboot 2.7
对拦截器不太明白时候,可以参考以下博文:
Springboot 拦截器(Interceptor)详解_、楽.的博客-CSDN博客_interceptor springboot
Spring Boot拦截器(Interceptor)详解_时间漏斗的博客-CSDN博客_interceptor order
Springboot 2.7
Swagger 2.9.0
· 问题复现
项目 启动报错(如图):
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
(1)swagger版本问题,升级3.0版本 (亲测对我项目无用)
(2)拦截器自定义各种写法,各种路径放开 (个人感觉 越看越迷)
(3)properties文件 的更改 (亲测对我项目无用)
Springboot1.5 继承 WebMvcConfigurerAdapter的写法,Springboot2.7版本升级已经不支持了,如图:

经查找资料理清有两种方式可实现自定义拦截器:
a、springboot2.0以后,mvc配置类从 WebMvcConfigurerAdapter 变成了 WebMvcConfigurationSupport,因此写法如下:

b、 需格外注意的是,在springboot2.0.0之后继承WebMvcConfigurationSupport类,要重写addInterceptors 和 addResourceHandlers 方法,以及 配置好静态资源路径 ,尤其是swagger-ui.html,不然会导致404,当然也不要忘记根据需要写跨域方法:

c、跨域 的 allowedOriguns("*") 也 变成了 allowedOriginPatterns("*"):

至此,项目正常启动,一切正常了,第一种方法结束;
a、实现 WebMvcConfigurer接口,一定要加上@EnableWebMvc 注解,告诉spring 我要完全自己控制mvc配置,也就是说所有配置自己重写,所有默认配置都没了;有博主说到这样写,有时会导致很多请求进不来,或者参数转换出错之类的,因为spring mvc默认的转换器已经不生效了,包括全局配置的Jackson也会失效;也不排除这种可能。
当然,目前我没有遇到,因为我重写的方法路径该放开的放开,该拦截的拦截了。

如果此处不加@EnableWebMvc 注解会报 文章开始的错误,导致项目运行不起来!!
b、加好@EnableWebMvc注解后,也不再需要 重写的方法了,因为会报红报错,所以注释或删掉 super.addInterceptors(registry); 、super.addResourceHandlers(registry); 并且同样要写好放开静态资源路径的代码,如图:

至此,方法二启动成功,项目一切正常了。
继承 mvc的配置类 WebMvcConfigurationSupport 的完整代码:
package cn.cinfotech.common.config;
import cn.cinfotech.filter.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
import javax.annotation.Resource;
/**
* @author fantong
* Springmvc 拦截器注册
*/
@Configuration
//@EnableWebMvc
//public class InterceptorConfig extends WebMvcConfigurerAdapter {
public class InterceptorConfig extends WebMvcConfigurationSupport {
//public class InterceptorConfig implements WebMvcConfigurer {
// @Autowired
@Resource
private LoginInterceptor loginInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
//注册拦截器
// registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/**");
registry.addInterceptor(loginInterceptor)
.addPathPatterns("/**")
.excludePathPatterns("/user/XXXXXX/XXXXXX","/XXXXXX/XXXXXX","/user/XXXXXX/XXXXXX","/XXXXXX/v2/alipay_callback", "/XXXXXX/iosPay","/error","/XXXXXX/v2/wxCallBack","/XXXXXX/v2/XXXXXX","/swagger-resources/**","/webjars/**","/static/**","/swagger-ui.html/**");//"/qrcode/v2/pc/inquireLoginState",
// .excludePathPatterns(String.valueOf(excludePath));
//在springboot2.0.0之后继承WebMvcConfigurationSupport类,重写addInterceptors方法
// *
super.addInterceptors(registry);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/")
.addResourceLocations("classpath:/resources/");
registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/");
registry.addResourceHandler("swagger-ui.html","doc.html").addResourceLocations("classpath:/META-INF/resources/");
//Windows下
registry.addResourceHandler("/uploads2/**").addResourceLocations("file:D:/springbootFile/upload/images/");
//Mac或Linux下(没有CDEF盘符)
registry.addResourceHandler("/uploads/**").addResourceLocations("file:/home/qmake/workspace/images/userImg/");
super.addResourceHandlers(registry);
}
/**
* 跨域支持
* @author QianChi
* @date 2021/6/30 9:55
*
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
// .allowedOrigins("*")
.allowedOriginPatterns("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH", "OPTIONS", "HEAD")
.maxAge(3600 * 24);
}
}
实现WebMvcConfigurer 接口的完成拦截器 代码:
package cn.cinfotech.common.config;
import cn.cinfotech.filter.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
import javax.annotation.Resource;
/**
* @author fantong
* Springmvc 拦截器注册
*/
@Configuration
@EnableWebMvc
//public class InterceptorConfig extends WebMvcConfigurerAdapter {
//public class InterceptorConfig extends WebMvcConfigurationSupport {
public class InterceptorConfig implements WebMvcConfigurer {
// @Autowired
@Resource
private LoginInterceptor loginInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
//注册拦截器
// registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/**");
registry.addInterceptor(loginInterceptor)
.addPathPatterns("/**")
.excludePathPatterns("/user/XXXXXX/XXXXXX","/XXXXXX/XXXXXX","/user/XXXXXX/XXXXXX","/XXXXXX/v2/alipay_callback", "/XXXXXX/iosPay","/error","/XXXXXX/v2/wxCallBack","/XXXXXX/v2/XXXXXX","/swagger-resources/**","/webjars/**","/static/**","/swagger-ui.html/**");//"/qrcode/v2/pc/inquireLoginState",
// .excludePathPatterns(String.valueOf(excludePath));
//在springboot2.0.0之后继承WebMvcConfigurationSupport类,重写addInterceptors方法
// *
// super.addInterceptors(registry);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/")
.addResourceLocations("classpath:/resources/");
registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/");
registry.addResourceHandler("swagger-ui.html","doc.html").addResourceLocations("classpath:/META-INF/resources/");
//Windows下
registry.addResourceHandler("/uploads2/**").addResourceLocations("file:D:/springbootFile/upload/images/");
//Mac或Linux下(没有CDEF盘符)
registry.addResourceHandler("/uploads/**").addResourceLocations("file:/home/qmake/workspace/images/userImg/");
// super.addResourceHandlers(registry);
}
/**
* 跨域支持
* @author QianChi
* @date 2021/6/30 9:55
*
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
// .allowedOrigins("*")
.allowedOriginPatterns("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH", "OPTIONS", "HEAD")
.maxAge(3600 * 24);
}
}
特此记录,踩坑日志
转载请注明出处:
我基本上来自Java背景并且努力理解Ruby中的模运算。(5%3)(-5%3)(5%-3)(-5%-3)Java中的上述操作产生,2个-22个-2但在Ruby中,相同的表达式会产生21个-1-2.Ruby在逻辑上有多擅长这个?模块操作在Ruby中是如何实现的?如果将同一个操作定义为一个web服务,两个服务如何匹配逻辑。 最佳答案 在Java中,模运算的结果与被除数的符号相同。在Ruby中,它与除数的符号相同。remainder()在Ruby中与被除数的符号相同。您可能还想引用modulooperation.
我在CentOS上运行一个ruby脚本,并通过rvm(1.9.3)安装了ruby。我已经在.bash_profile中设置了NLS_LANG变量。[app@boxstasis]$echo$NLS_LANGen_US.UTF-8[app@boxstasis]$whichruby~/.rvm/rubies/ruby-1.9.3-p194/bin/ruby然而,当试图通过ruby(oci8驱动程序所做的)访问它时,它找不到它:1.9.3-p194:001>ENV['NLS_LANG']=>nil访问其他变量似乎有效:1.9.3-p194:004>ENV['USER']=>"app
在为一些与JRuby中的临时文件交互的代码运行单元测试时,我有时会得到以下信息:Exception:java.lang.ThreadDeaththrownfromtheUncaughtExceptionHandlerinthread"Thread-6395"它似乎没有引起任何问题,但这是怎么回事,我如何确定它发生在哪里?我尝试打开-d,但这并没有给我异常的堆栈跟踪。 最佳答案 FWIW:这可能与http://jira.codehaus.org/browse/JRUBY-7074有关.我偶尔会在不使用反引号但调用系统的JRuby程序中
1.在使用Assert.assertEquals时报一个错误:2.首先,我们的明白Assert的用法:assert如果为true,则程序继续执行。如果为false,则程序抛出AssertionError,并终止执行assert:如果为true,则程序继续执行。如果为false,则程序抛出java.lang.AssertionError,并输出。ctrl点进Assert.assertEquals发现进行的是判断两个Object类型的值,他们两个比较的是引用地址是否相等,并没有对内容进行比较:如果两者一致,程序继续往下运行.如果两者不一致,中断测试方法,抛出异常信息AssertionFai
如何在Web应用程序中动态设置HTML的“lang”属性?我尝试使用jQuery如下插入“lang”属性:$(document).ready(function(){$("html").attr("lang",language);//'language'valueisretrievedfromacookie});使用控制台/警报,'lang'属性看起来已按预期设置。但是,如果您看到生成的源代码(查看源代码),则根本没有设置“lang”。要求是屏幕阅读器必须能够动态识别语言。如果有任何其他解决方案可以使屏幕阅读器动态识别语言,那就太好了。感谢大家在线发表评论!
我正在尝试使用GJS(GnomeJavascript)开发GnomeShell扩展,但是,我遇到了Lang库(我认为它是一个库,如果我不正确的话)。但是我在网上找不到任何关于它的资源。在代码中它看起来像这样:constLang=imports.lang;constObjectA=newLang.Class({...});我在哪里可以找到有关它的文档?它是Gnome库吗?Mozilla库? 最佳答案 它是gjs的内置模块--参见modules/lang.js.它包括两个主要部分:bind()(使“this”指向闭包中的逻辑对象的助手)
这个问题在这里已经有了答案:JSfunctionnamed`animate`doesn'tworkinChrome,butworksinIE(3个答案)关闭6年前。在我的HTML中,我在script标签中定义了lang函数并添加了“TestFire!”单击时必须调用lang的按钮:TestingFunctionsfunctionlang(){alert("Hello,World!It'sJavaScriptthistime");}但是,如果我点击按钮,我会得到这个错误:UncaughtTypeError:langisnotafunction但是,如果我将函数名称从lang更改为任何其他
如何在golang中对4.3.4、4.3.30等字符串进行排序。golang中有一个名为“sort”的方法?问题是使用此方法4.3.30在4.3.4之前打印。我希望4.3.30在4.3.4之后打印。这种排序的逻辑是什么?注意-我只需要一个逻辑天气,它将在go或java中。提前致谢。供您引用,go中的“排序”程序:packagemainimport"sort"import"fmt"typeByLength[]stringfunc(sByLength)Len()int{returnlen(s)}func(sByLength)Swap(i,jint){s[i],s[j]=s[j],s[i]}
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭5年前。Improvethisquestion我需要咨询或示例代码,了解如何向客户发送JSON中的多个元素。谢谢!我需要下一个JSON结构:{{"id":123,"first_name":"Demo","last_name":"User","time":"2017-07-03T16:36:41.4101847Z","count":1,"payout":"839`"},{"id":124,"first_name":"Demo","last_na
我的Gointellisense自动完成功能不工作,我正在尝试安装gocode和gopkg但它失败了,并给出了类似git的错误:::cd/home/poojat/go/src/golang.org/x/tools;gitpull--ff-onlyerror:Yourlocalchangestothefollowingfileswouldbeoverwrittenbymerge:CONTRIBUTING.mdREADMEblog/blog.gocmd/bundle/main.gocmd/callgraph/main.gocmd/callgraph/main_test.gocmd/call