千云物流- 使用spring家族常见问题

本文档列举了使用Spring框架遇到的一些问题及其解决办法,包括:Spring版本问题、WebMvcConfigurer配置HandlerInterceptor失效、RocketMQ连接问题、RocketMQ消费端内存问题、Redis问题、WebFlux对接问题、认证授权网关接入问题、前端Vue打包部署、Spring Boot加载jar、Druid SQL监控未显示、以及Spring+JPA+Atomikos+XA分布式事务多数据源配置问题。针对这些问题,文中提供了相应的排查思路和调整建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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注解,在前端传
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

青0721松

你的鼓励将是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值