我正在使用带有Jersey 2.1 的Spring Boot和 Ionic 来开发一个应用程序,我已经尝试了我找到的每一个帖子,但没有一个帖子为我解决了这个问题,我得到的错误包括那些关于@PATCH自己创建界面注释的内容。因此,问题是在执行PATCH请求时在浏览器上进行测试时,我在客户端收到此错误:CORS 策略已阻止从源“ http://localhost:8100 ”访问 XMLHttpRequest :预检响应中的 Access-Control-Allow-Methods 不允许方法 PATCH。我用于响应的过滤器如下,如果我有PATCH一个允许的方法并且它在 Postman 上完美运行,我不明白为什么我会得到这个:筛选:@Providerpublic final class ResponseFilter implements ContainerResponseFilter { @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { MultivaluedMap<String, Object> headers = responseContext.getHeaders(); headers.putSingle("Accept-Patch", "*"); headers.putSingle("Access-Control-Allow-Origin", "*"); headers.putSingle("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE, PATCH"); headers.putSingle("Access-Control-Allow-Credentials", "true"); headers.putSingle("Access-Control-Max-Age", "3600"); headers.putSingle("Access-Control-Allow-Headers", "Content-Type, Accept, Authorization"); }}使用的方法PATCH:import javax.ws.rs.PATCH;@PATCH @Path("/{username}")@Produces(MediaType.APPLICATION_JSON) public Response actualizarPassword(@Valid @NotNull(message = "user must not be null") final UserDTO userDTO, @PathParam("username") final String username, @QueryParam("codigo") @NotNull(message = "codigo musnt be null") final String codigo) { userDTO.setUsername(username); this.usersService.actualizarPassword(this.userDTOMapper.map(userDTO), codigo); return Response.noContent().build(); }正如我所说,我还尝试创建一个注释,PATCH正如我在一些答案中阅读的那样,但是这个 http 方法应该包含在 Jersey 2.1 中,并且确实就像在上一段代码中看到的那样,我创建的接口曾是:@Target({ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@HttpMethod("PATCH")public @interface PATCH {}
添加回答
举报
0/150
提交
取消