美文网首页
spring cloud config server 整合 eu

spring cloud config server 整合 eu

作者: 兴厚 | 来源:发表于2019-04-01 14:17 被阅读0次

这是在整合注册中心时出现的问题(别的注册中心没试,但应该也会出现), 版本说明

 <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>Greenwich.RELEASE</version>
      <type>pom</type>
      <scope>import</scope>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.1.3.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

访问配置中心的一个某个配置文件信息,返回xml格式数据(正常来讲应该是json数据),解决方法, 在入口类实现 org.springframework.web.servlet.config.annotation.WebMvcConfigurer 接口,重写 configureContentNegotiation default方法:

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
    configurer.ignoreAcceptHeader(true).defaultContentType(MediaType.APPLICATION_JSON_UTF8);
}

这个方法会忽略浏览器发送的 accept header,强制返回 json 格式的数据。修改了 sevelet 的创建工厂配置(项目的配置类实现这个接口也行)。

相关文章

网友评论

      本文标题:spring cloud config server 整合 eu

      本文链接:https://www.haomeiwen.com/subject/emlvbqtx.html