Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Errai JAX-RS-找不到POST的资源方法,返回405和Allow标头_Java_Gwt_Errai - Fatal编程技术网

Java Errai JAX-RS-找不到POST的资源方法,返回405和Allow标头

Java Errai JAX-RS-找不到POST的资源方法,返回405和Allow标头,java,gwt,errai,Java,Gwt,Errai,我在Errai Jax rs上遇到了问题,我不确定这为什么不起作用: @Path("userservice") public interface UserService { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public void login(LoginForm login); } 从UI调用时: service.call(n

我在Errai Jax rs上遇到了问题,我不确定这为什么不起作用:

@Path("userservice")
public interface UserService {
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public void login(LoginForm login);
}
从UI调用时:

    service.call(new RemoteCallback<Void>() {
        @Override
        public void callback(Void response) {
                         // Do stuff        
        }
    }, new ErrorCallback() {
        @Override
        public boolean error(Message message, Throwable throwable) {
            return false;
        }
    }).login(new LoginForm(this.username.getText(),
            this.password.getText(),
            true)); 

我在尝试使用错误数量的参数访问我的方法时遇到此异常

我打电话:
http://localhost:8080/my-应用程序/我的服务/参数1


而服务期望:
http://localhost:8080/my-app/my service/param1/param2

在尝试通过RestEasy访问服务时,我遇到了相同的异常。因此,如果其他人偶然发现它:

正如Andreas已经提到的,它经常引用错误的URL

在我的情况下,我可以通过邮递员或resteasy target呼叫我的服务

final String path = "http://localhost:8080/repository/user";
e、 g

在使用Resteasy代理时,我必须使用

final String path = "http://localhost:8080/repository";
e、 g


发生此错误的原因通常是rest/endpoint地址不可用:

  • 检查类名上方的@Path注释
  • 检查方法名称上方的@Path注释
  • 如果您使用@PathParam或@QueryParam注释,请确保有两件事:

    • 该值对应于方法签名中声明的类型
    • 检查是否传递了正确数量的参数
    • 所有注释导入实际上都来自包javax.ws.rs

  • 如果错误仍然存在,请尝试检查CORS实现(如果有的话)。

    您确定可以在JAX-RS中使用
    void
    返回类型吗?(顺便说一句,这里与Errai无关,它是服务器端的JAX-RS,使用Resteasy作为实现)是的,@Override public void login(LoginForm login){}否,我的意思是,JAX-RS(JSR 311/JSR 339),顺便说一句Resteasy,是否允许资源方法的返回类型为
    void
    ?我检查了规范,它是允许的(将映射到HTTP 204状态代码);所以这不是这里的问题。UserService的实现是否会改变login()方法的
    @消费
    @生产
    内容类型?它是否在类或方法级别重写了
    @Path
    值?@jonathanfurth,不,我不这么认为,因为注释只在接口上
            Client client = ClientBuilder.newBuilder().build();
            WebTarget target = client.target("http://localhost:8080/repository/user");
            Response response = target.request().get();
    
    final String path = "http://localhost:8080/repository";
    
        ResteasyClient client = new ResteasyClientBuilder().build();
        ResteasyWebTarget target = client.target(UriBuilder.fromPath("http://localhost:8080/repository"));
        IUserTestRepository proxy = target.proxy(IUserTestRepository.class);