Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 添加xml支持后,响应的内容类型设置为application/xml_Spring_Spring Boot - Fatal编程技术网

Spring 添加xml支持后,响应的内容类型设置为application/xml

Spring 添加xml支持后,响应的内容类型设置为application/xml,spring,spring-boot,Spring,Spring Boot,我的另一个棘手的问题。 我有rest api控制器: @RestController() @RequestMapping("/api/project") public class ProjectController{ @PreAuthorize("hasAuthority('ROLE_USER')") @GetMapping(value = "/{id}/severitychart") public ResponseEntity<HashMap<String,

我的另一个棘手的问题。 我有rest api控制器:

@RestController()
@RequestMapping("/api/project")
public class ProjectController{
    @PreAuthorize("hasAuthority('ROLE_USER')")
    @GetMapping(value = "/{id}/severitychart")
    public ResponseEntity<HashMap<String,Long>> showSeverityChart(@PathVariable("id")Long id) {
        return projectService.showSeverityChart(id);
    }
}
@RestController()
@请求映射(“/api/project”)
公共类项目控制器{
@预授权(“hasAuthority('ROLE_USER'))
@GetMapping(value=“/{id}/severitychart”)
公共响应属性showSeverityChart(@PathVariable(“id”)长id){
返回projectService.showSeverityChart(id);
}
}
它工作得很好,返回了
JSON
响应

后来,我不得不添加
XML
的处理——没什么特别的,只是简单地解析给定的
XML
消息并将其存储到数据库中。不过,所有响应都应该映射到JSON
,这是使用
JAXBContext完成的`

从现在起,API调用的每个响应都返回XML结构化对象,标题为
内容类型:application/XML

是否可以保持服务原样并仍然使用默认的JSON映射

我不想在每个端点上放置
products=“application/json”

@EnableWebMvc
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
    @Override
    public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
        configurer.defaultContentType(MediaType.APPLICATION_JSON);
    }
}