栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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 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
rocketmq连接出现连接不上的问题

控制台日志: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。

redis出现的问题 webflux对接常见问题

错误信息:org.springframework.web.server.ResponseStatusException: 404 NOT_FOUND at
org.springframework.web.reactive.resource.ResourceWebHandler.lambda$handle$0(ResourceWebHandler.java:325)
检查路径是否有配置。配置是否生效。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/946221.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号