Wildfly 15.0.1 JAX-RS @BeanParam NPE的getter方法

问题描述 投票:0回答:1

我在Wildfly 15.0.1测试JAX-RS annoration @BeanParam,而是试图通过getter方法来访问字段值当我得到NPE。

如果我使用@FormParam代替,一切工作正常。在Eclipse调试器,如果我直接访问字段(未通过getter方法)的值是存在的。不过,如果我尝试通过它的getter方法来访问字段值,则返回null,因此NPE。以下是Eclipse调试器的屏幕截图示出了字段具有值,但是吸气剂方法返回null。

enter image description here

enter image description here

什么我试图做的代码片段:

@RequestScoped  
public class TestFilter {  
    @FormParam("date_fr")  
    private String dateFr;  
    ...  
}  

@ApplicationScoped  
@Path("/test")  
public class TestRes {  
    @POST  
    @Path("/search")  
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)  
    public Response search(@BeanParam TestFilter filter) throws IOException {  
        if (filter.getDateFr().length() > 0) { // NPE here: filter.getDateFr() is null  

        }  
    }  
}  

任何人都知道这是怎么回事这里的@BeanParam?难道我做错了什么?

java jax-rs wildfly resteasy
1个回答
0
投票

罪魁祸首是@RequestScoped注解。不这样做,它按预期工作。

有人报告对该一个吉拉错误:https://issues.jboss.org/browse/WFLY-11680

© www.soinside.com 2019 - 2024. All rights reserved.