Home  >  Article  >  Java  >  How to solve the problem that SpringBoot integrates Eureka and causes the return result to change from json to xml

How to solve the problem that SpringBoot integrates Eureka and causes the return result to change from json to xml

王林
王林forward
2023-05-15 15:16:061066browse

SpringBoot integrating Eureka causes the return result to change from json to xml

Solution

Add

produces = { “application/json;charset=UTF-8” }

to the requested Mapping. For example:

@GetMapping(value = "/user-instance", produces = { "application/json;charset=UTF-8" })

The following are json and xml

@GetMapping(value = "/user-instance", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@GetMapping(value = "/user-instance", produces = MediaType.APPLICATION_XML_VALUE)

Supports return in JSON and XML formats

Sometimes the project requires two return formats. At this time, we only need to add the dependency of jackson xml

<dependency>
  <groupId>com.fasterxml.jackson.jaxrs</groupId>
  <artifactId>jackson-jaxrs-xml-provider</artifactId>
</dependency>

eureka fails to start and returns xml information

1. Why should this be used

After starting eclipse as usual today, I started the eureka project and accessed the corresponding eureka but returned a lot of xml Information, but no error is reported when looking at the console. It's a very strange situation. Du Niang can't even find relevant information. There is a similar question on Google. There is a prompt below that says to add a line of configuration to the configuration file. I tried it and it still failed.

2. Solution

After trying various methods to no avail, I decided to start with maven.

For the first time, find the repository path under your maven configuration, (windows-preference-maven-user settings local repository)

Enter org/springframework and delete the cloud folder (need to close eclipse ), then open eclipse, update the project, and start eureka again after completion. The problem is still not solved, so it is not a problem with the cloud package.

The second time, very cruelly, I deleted the entire springframework folder and downloaded it again. success. eureka access returns to normal.

The above is the detailed content of How to solve the problem that SpringBoot integrates Eureka and causes the return result to change from json to xml. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete