【问题标题】:Resteasy client intialization causes Unable to find contextual data of type: javax.servlet.ServletContextResteasy客户端初始化导致无法找到类型的上下文数据:javax.servlet.ServletContext
【发布时间】:2019-10-08 20:05:01
【问题描述】:

我正在使用 Mandrill,并且我在 Wildfly 18 上使用 resteasy 客户端为用户设置了一个界面

public interface MandrillServiceRest extends ServiceRest {

    @POST
    @Path("/messages/send-template.json")
    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_JSON})
    Response sendTemplate(@HeaderParam("User-Agent") String userAgent, final MandrillSendTemplateRequest mandrillSendTemplateRequest);

    @POST
    @Path("/messages/send.json")
    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_JSON})
    Response send(@HeaderParam("User-Agent") String userAgent, final MandrillSendRequest mandrillSendRequest);

    @POST
    @Path("/users/ping2.json")
    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_JSON})
    MandrillPong ping(@HeaderParam("User-Agent") String userAgent, final MandrillPing mandrillPing);

    @POST
    @Path("/templates/info.json")
    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_JSON})
    Response templatesInfo(@HeaderParam("User-Agent") String userAgent, final MandrillTemplateInfoRequest mandrillTemplateInfoRequest);


    @POST
    @Path("/templates/add.json")
    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_JSON})
    Response addTemplate(@HeaderParam("User-Agent") String userAgent, final MandrillTemplateAddOrUpdateRequest mandrillTemplateAddOrUpdateRequest);

    @POST
    @Path("/templates/update.json")
    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({MediaType.APPLICATION_JSON})
    Response updateTemplate(@HeaderParam("User-Agent") String userAgent, final MandrillTemplateAddOrUpdateRequest mandrillTemplateAddOrUpdateRequest);
}

看起来不错,但是当我创建客户端时:

ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();           ResteasyProviderFactory.pushContext(javax.ws.rs.ext.Providers.class, factory);
        ResteasyClientBuilder resteasyClientBuilder = new ResteasyClientBuilder().providerFactory(factory);
        resteasyClientBuilder.connectionPoolSize(20);
        resteasyClientBuilder.socketTimeout(5000, TimeUnit.SECONDS);
        ResteasyClient resteasyClient = resteasyClientBuilder.build();
        WebTarget target = resteasyClient.target("https://mandrillapp.com/api/1.0");
        ResteasyWebTarget resteasyWebTarget = (ResteasyWebTarget) target;
        MandrillServiceRest mandrillServiceRest = resteasyWebTarget.proxy(MandrillServiceRest.class);

并发生此错误:

org.jboss.resteasy.spi.LoggableFailure: RESTEASY003880: Unable to find contextual data of type: javax.servlet.ServletContext

我目前正在尝试检查一个新的空白项目...

顺便说一句,它曾经在wildfly 10中工作

【问题讨论】:

  • 如果您不提供有关您所看到的错误/问题的任何详细信息,很难提供答案
  • 当然。到目前为止,我一直在挖掘,这是另一个 ServletContext not found 异常。醒来后我会编辑问题????
  • 更新完成,-> org.jboss.resteasy.spi.LoggableFailure: RESTEASY003880: 找不到上下文数据类型:javax.servlet.ServletContext

标签: wildfly resteasy


【解决方案1】:

我删除了 ResteasyProviderFactory 的使用,它运行良好。真不知道为什么。我稍后会检查,但如果有人知道,我很高兴阅读解释:)

【讨论】:

    猜你喜欢
    • 2013-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    相关资源
    最近更新 更多