Home > Java > javaTutorial > 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

王林
Release: 2023-05-15 15:16:06
forward
1133 people have browsed it

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

Solution

Add

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

to the requested Mapping. For example:

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

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)
Copy after login

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>
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template