spring使用版本导致的问题
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<WebMvcConfigurer> configurers) {
if (!CollectionUtils.isEmpty(configurers)) {
this.configurers.addWebMvcConfigurers(configurers);
}
}
}
2.0之后使用配置
第一种WebMvcConfigurer配置
/**
* 在spring上下文生效
*/
@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
rocketmq连接出现连接不上的问题
控制台日志:RocketmqRemoting: closeChannel: close the connection to remote address[139.186.167.86:11306] result: true
spring配置rocket连接在测试环境一直不能连接,别的几个项目都可以正常连接,但是到了某个服务不能正常连接
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
<versinon>2.1.1.RELEASE</versinon>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.3</version>
</dependency>
对应的fastJosn版本调整1.x后正常可以访问
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.72</version>
</dependency>
一直没有怀疑到fastjson问题。
事后分析:
跟踪定位是fastjson出问题,在rocket的交互的包一定是在序列化会出现问题,RemotingSerializable类中应用了fastjson。导致在序列化的方法不存在。导致 channel通道释放。没有进行心跳包的传递。在netty的远程传输序列化使用的是fastjson。
rocketmq消费端内存爆满的问题
场景描述:运行一段时间内存会爆满到6G左右
对应处理:在启动时候配置-Drocketmq.client.logFileMaxSize=67108864,
redis出现的问题
webflux对接常见问题
错误信息:org.springframework.web.server.ResponseStatusException: 404 NOT_FOUND at
org.springframework.web.reactive.resource.ResourceWebHandler.lambda$handle$0(ResourceWebHandler.java:325)
- 检查路径是否有配置。配置是否生效。
- 是否使用了springweb中的@RequestParam注解,在前端传