zoukankan      html  css  js  c++  java
  • spring boot 与spring boot admin整合问题处理

    1.在整合springboot admin server时,发现admin client无法注册到admin server上

    查找原因后发现代码中报错:HttpMediaTypeNotAcceptableException: Could not find acceptable representation

    2.此时知道是返回给admin server类型时发生的错误,但是不知道admin server需要的是什么类型,所以重写WebMvcConfigurer

    解析全部类型查看返回类型是什么

     @Override
        public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
            for (HttpMessageConverter<?> converter : converters) {
                if (converter instanceof MappingJackson2HttpMessageConverter) {
                    converters.remove(converter);
                }
            }
            FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
            List<MediaType> supportedMediaTypes = new ArrayList<>();
            //解析全部类型
            supportedMediaTypes.add(MediaType.ALL);
    
            converter.setSupportedMediaTypes(supportedMediaTypes);
            FastJsonConfig fastJsonConfig = new FastJsonConfig();
            fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteDateUseDateFormat,
                    SerializerFeature.WriteNullStringAsEmpty,
                    SerializerFeature.WriteMapNullValue,
                    SerializerFeature.DisableCircularReferenceDetect);
            //日期格式化
            fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
            converter.setFastJsonConfig(fastJsonConfig);
            converters.add(converter);
        }

    3.调用接口,返回结果成功,得知需要的类型为:application/vnd.spring-boot.actuator.v2+json

    4.添加对类型application/vnd.spring-boot.actuator.v2+json的解析

            //提供对admin的类型支持mediaType
            MediaType mediaType = MediaType.valueOf("application/vnd.spring-boot.actuator.v2+json");
            supportedMediaTypes.add(mediaType);
  • 相关阅读:
    bzoj4753: [Jsoi2016]最佳团体(分数规划+树形依赖背包)
    bzoj2956: 模积和(数论)
    51nod 1766 树上的最远点对(线段树)
    bzoj2621: [Usaco2012 Mar]Cows in a Skyscraper(状压DP)
    Codeforces Round #441 Div. 2题解
    bzoj4569: [Scoi2016]萌萌哒(ST表+并查集)
    iOS和Android后台机制对比
    UIApplicationDelegate 各方法回调时机
    iOS OC和JS的交互 javaScriptCore方法封装
    iOS应用的执行原理
  • 原文地址:https://www.cnblogs.com/yechen2019/p/11791106.html
Copyright © 2011-2022 走看看