解决spring boot与spring boot admin整合的问题
最编程
2024-08-15 14:34:32
...
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);
原文地址:https://www.cnblogs.com/yechen2019/p/11791106.html
推荐阅读
-
解决spring boot与spring boot admin整合的问题
-
前言:基于Spring Boot的设计与实现的Java毕业设计-风景线旅游网站的实施
-
深入理解Spring Boot 2.0.3中的装饰模式与自定义会话管理
-
Spring Boot项目搭建指南:轻松实现JSP与注解开发的完美兼容,包含详细步骤与两种配置方法
-
Spring Boot中的RestTemplate配置与应用教程
-
Spring Boot 3和Redis:探索基本数据类型的使用方法与背景知识
-
实战指南:Spring Boot与Spring Cloud的OAuth2集成详解
-
解决Spring Boot和Vue之间跨域交互的问题
-
打造高校健康管理系统的Java、Spring Boot与Vue框架实践
-
搞定 Spring Boot 与 RabbitMQ 的整合,这篇文章让你一学就会!