我想使用我的控制器使用Spring MVC拦截OPTIONS请求,但它被DispatcherServlet捕获.我该如何管理?
我正在尝试为处理COPY HTTP方法的资源创建自定义Spring MVC Controller.
@RequestMapping仅接受以下RequestMethod值:GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS和TRACE.
在Spring MVC Controller中是否有任何推荐的处理自定义HTTP方法的方法?
我在服务器端使用Spring Boot,在客户端使用Angularjs,我使用Filter配置Spring Boot应用程序CORS,它适用于GET,POST方法,但是,当我尝试使用$ http模块发送PUT请求时,我得到了这个在我的浏览器控制台:
注意:url = http:// localhost:8080/localbusinessusers/[object%20Object]
选项url (匿名函数)@ angular.js:11442sendReq @ angular.js:11235serverRequest @ angular.js:10945processQueue @ angular.js:15552(匿名函数)@ angular.js:15568Scope.$ eval @ angular.js:16820Scope. $ digest @ angular.js:16636Scope.$ apply @ angular.js:16928done @ angular.js:11266completeRequest @ angular.js:11464requestLoaded @ angular.js:11405 app.html:1 XMLHttpRequest无法加载 网址.预检的响应具有无效的HTTP状态代码405 angular.js:11442 XHR加载失败:PUT" url ".
我在Spring Boot控制台上得到了这个:
2016-03-08 23:19:51.212 WARN 27044 --- [XNIO-2 task-2] osweb.servlet.PageNotFound:不支持请求方法'OPTIONS'
我的CORS 过滤器:
package com.datcom.fouras;
import …Run Code Online (Sandbox Code Playgroud) 我有一个 Spring boot API 作为服务器,还有一个 Angular JS 前端应用程序。从前端我收到此错误:
Access to XMLHttpRequest at 'http://localhost:8080/?latitude=38.902693&longitude=-77.011932' from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Run Code Online (Sandbox Code Playgroud)
这是我的 spring 应用程序及其配置:
WebConfiguration.java:
package com.example.assignment.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
@EnableWebMvc
public class WebConfiguration implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedOrigins("*")
.allowedHeaders("Content_Type", "Authorization");
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序配置.java: …