1

在我的带有 RESTful WebService 的 Java Web 应用程序中,我使用的是 Wildfly 8.2,它具有焊接 2.2.6。我在线程中注入 HttpServletRequest 对象并从中读取参数。使用焊接 3.0.3 升级到 Wildfly 12.0 后,在线程中使用 HttpServletRequest 实例会出现以下错误:

org.jboss.weld.contexts.ContextNotActiveException:WELD-001303:范围类型 javax.enterprise.context.RequestScoped 没有活动上下文

有没有办法解决这个问题?

我尝试了 Wildfly 12 的焊接 3.0.4 补丁更新,尝试使用 AsyncContext。尝试作为@context 注入。此代码在 Wildfly 12 中运行良好,它甚至在 Wildfly 16 中都无法运行。

@Path("test")
public class TestWildfly12 {

    @Inject
    private HttpServletRequest request1;

    @GET
    public Response testRequest() {

        request1.setAttribute("test", "test");
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.execute(() -> {

            Object value = request1.getAttribute("test");
            System.out.println(value);
        });

        final Response response = Response.build().entity(true);
        response.setStatus(Status.OK.getStatusCode());

        return response;
    }
}

我希望代码从线程中的请求参数中获取数据。

4

0 回答 0