相关疑难解决方法(0)

CORS:AngularJS + Resteasy 3 + Wildfly

我正在使用AngularJS和Resteasy开发一个应用程序.正如所料,我面临众所周知的问题

XMLHttpRequest cannot load http://localhost:8080/..... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 403.

正如在其他堆栈溢出帖[1]上看到的,我尝试使用来自Feature对象的Resteasy的CorsFilter,但我得到:

[33m02:06:57,883 WARN  [org.jboss.resteasy.core.ExceptionHandler] (default task-1) failed to execute: javax.ws.rs.ForbiddenException: Origin not allowed: http://localhost:3000
    at org.jboss.resteasy.plugins.interceptors.CorsFilter.checkOrigin(CorsFilter.java:194)
    at org.jboss.resteasy.plugins.interceptors.CorsFilter.filter(CorsFilter.java:134)
Run Code Online (Sandbox Code Playgroud)

我的CorsFeature对象:

@Provider
public class CorsFeature implements Feature {

    @Override
    public boolean configure(FeatureContext context) {
        CorsFilter corsFilter = new CorsFilter();
        corsFilter.getAllowedOrigins().add("*");
        context.register(corsFilter);
        return true;
    }  
}
Run Code Online (Sandbox Code Playgroud)

web.xml中我添加了:

<context-param>
    <param-name>resteasy.providers</param-name> …
Run Code Online (Sandbox Code Playgroud)

jboss resteasy cors angularjs

5
推荐指数
1
解决办法
8848
查看次数

标签 统计

angularjs ×1

cors ×1

jboss ×1

resteasy ×1