Spring MVC控制器忽略“消耗”。属性 [英] Spring MVC controller ignores "consumes" property

查看:120
本文介绍了Spring MVC控制器忽略“消耗”。属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有控制器:

@RestController
@RequestMapping(value = "/v1/mail", consumes = {APPLICATION_JSON_VALUE})
@ResponseStatus(OK)
public class MailController {

    private CoreOutRestAdapter coreAdapter;

    @Autowired
    public MailController(CoreOutRestAdapter coreAdapter) {
        this.coreAdapter = coreAdapter;
    }

    @RequestMapping(method = POST)
    public void sendMail(@RequestBody @Validated Mail mail) {
        coreAdapter.sendMail(mail);
    }

}

和jackson-databind 2.3.2在classpath中。但是如果我使用Content-Type:application / json发送POST请求,则返回的响应包含415状态(Unsupported Media Type)。我不明白为什么控制器忽略@RequestMapping注释中的消耗属性。我怎样才能解决这个问题?此外,您可以在github找到项目的其余部分 https://github.com/f1xmAn/scail

and jackson-databind 2.3.2 in classpath. But if I send POST request with Content-Type: application/json, returned response contains 415 status (Unsupported Media Type). I don't understand why controller ignores "consumes" property in @RequestMapping annotation. How can I fix this? Also, the rest of project you can find at github https://github.com/f1xmAn/scail

推荐答案

我忘了用@EnableWebMvc注释配置。注释后控制器工作正常。

I forgot annotate config with @EnableWebMvc. After annotating controller works fine.

这篇关于Spring MVC控制器忽略“消耗”。属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆