解决方法一: 去除依赖的包
因为在eureka-server start里面带了 format-xml的包,而且转xml优先级高于json。所以加入依赖后原json 变成了xml格式
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<!-- 去除依赖的包 -->
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</exclusion>
</exclusions>
</dependency>
解决方法二: 指定MediaType的类型
@RequestMapping(value="/index", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)