【发布时间】:2017-10-23 20:11:09
【问题描述】:
我正在尝试在 Spring Security 4.2.3.RELEASE 上启用 CORS。 spring-mvc.xml
<mvc:mapping path="/rest/**"
allowed-origins="*"
allowed-methods="GET, POST, HEAD, OPTIONS, PUT, DELETE"
allowed-headers="Content-Type, X-Requested-With,accept, Origin,Access-Control-Request-Method, Access-Control-Request-Headers, Authorization"
exposed-headers="Access-Control-Allow-Origin,Access-Control-Allow-Credentials"
allow-credentials="false"
max-age="10" />
</mvc:cors>
spring-security.xml
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<http pattern="/rest/**" use-expressions="true" entry-point-ref="unauthorizedEntryPoint" create-session="stateless">
<csrf disabled="true"/>
<cors/>
<custom-filter before="FORM_LOGIN_FILTER" ref="jwtAuthenticationFilter"/>
</http>
尝试部署时: 原因:org.springframework.beans.factory.BeanCreationException:无法创建CorsFilter
【问题讨论】:
-
你没有在
web.xml中初始化CORSFilterbean。 -
你有例子吗?这里没有提到对 web.xml docs.spring.io/spring-security/site/docs/4.2.x/reference/html/… 的任何更改
-
完整的异常堆栈跟踪会很有帮助
标签: spring-mvc spring-security cors