Spring Rest-API - 403禁止错误响应

时间:2015-10-11 17:34:12

标签: java spring rest

我是春天的新手,我正在编写REST API。删除时,我得到403禁止错误,put。以下是我正在研究的样本。

@RequestMapping(value = "/{noteId}", method = RequestMethod.PUT)
    public ResponseEntity noteIdPut(
            @PathVariable("Id") String Id,
            Note note)
            throws Exception {
        return service.updateNote(Id, note);
    }

1 个答案:

答案 0 :(得分:3)

只需在web.xml中添加这些过滤行。

<filter>
        <filter-name>CorsFilter</filter-name>
        <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
        <init-param>
            <param-name>cors.allowed.origins</param-name>
            <param-value>*</param-value>
        </init-param>
        <init-param>
            <param-name>cors.allowed.headers</param-name>
            <param-value>Content-Type,X-Requested-With,accept,authorization,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
        </init-param>
        <init-param>
        <param-name>cors.allowed.methods</param-name>
        <param-value>GET, POST, PUT, DELETE, OPTIONS, HEAD</param-value>
    </init-param>
    </filter>