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)
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>
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.
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!