https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E
WebMvcConfigurer配置HandlerInterceptor拦截器失效第一检查包扫描是否能扫上,
第二检查是否有WebMvcConfigurationSupport和spring配置生效的问题。
| 对应sping版本 | 对应拦截需要配置的类 |
|---|---|
| spring2.0之前 | WebMvcConfigurerAdapter |
| spring2.0之后 | WebMvcConfigurationSupport或WebMvcConfigurer,HandlerInterceptor |
2.0之前使用配置
@Configuration
public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {
private final WebMvcConfigurerComposite configurers = new WebMvcConfigurerComposite();
public DelegatingWebMvcConfiguration() {
}
@Autowired(
required = false
)
public void setConfigurers(List configurers) {
if (!CollectionUtils.isEmpty(configurers)) {
this.configurers.addWebMvcConfigurers(configurers);
}
}
}
2.0之后使用配置
第一种WebMvcConfigurer配置
@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@Order(-1)
public class WebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addWebRequestInterceptor(webRequestWarpInterceptor()).addPathPatterns("/**");
}
}
第二种WebMvcConfigurer配置
@Component
public class SelfHandlerInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
// 具体实现百度吧
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
throws Exception {
//具体请百度
}
}
注意事项
WebMvcConfigurationSupport和WebMvcConfigurer只能选择一种进行配置。
- SpringBoot做了这个限制,只有当WebMvcConfigurationSupport类不存在的时候才会生效WebMvc自动化配置,如果继承了WebMvcConfigurationSupport,就不能使用WebMvcConfigurer相关的配置
- 在swagger引入的时候需要注意。不要使用WebMvcConfigurationSupport做配置要实现WebMvcConfigurer
控制台日志:RocketmqRemoting: closeChannel: close the connection to remote address[139.186.167.86:11306] result: true
spring配置rocket连接在测试环境一直不能连接,别的几个项目都可以正常连接,但是到了某个服务不能正常连接
com.alibaba.cloud spring-cloud-starter-stream-rocketmq 2.1.1.RELEASE com.alibaba fastjson 2.0.3
对应的fastJosn版本调整1.x后正常可以访问
com.alibaba fastjson 1.2.72
一直没有怀疑到fastjson问题。
事后分析:
跟踪定位是fastjson出问题,在rocket的交互的包一定是在序列化会出现问题,RemotingSerializable类中应用了fastjson。导致在序列化的方法不存在。导致 channel通道释放。没有进行心跳包的传递。在netty的远程传输序列化使用的是fastjson。
错误信息:org.springframework.web.server.ResponseStatusException: 404 NOT_FOUND at
org.springframework.web.reactive.resource.ResourceWebHandler.lambda$handle$0(ResourceWebHandler.java:325)
检查路径是否有配置。配置是否生效。



