【问题标题】:SEVERE: StandardWrapper.Throwable in jax-rs maven project严重:jax-rs maven 项目中的 StandardWrapper.Throwable
【发布时间】:2015-11-30 12:17:26
【问题描述】:

添加以下代码后:

@GET
@Produces({"application/xml", "application/json"})
public WatchList find(@PathParam("id") Integer id) {
    WatchList results = em.createNamedQuery("WatchList.findById", WatchList.class)
            .setParameter("id", id)
            .getSingleResult();
    return results;
}

@GET
@Path("{id}")
@Produces(MediaType.TEXT_HTML)
public void findById(
        @Context final HttpServletRequest request,
        @Context final HttpServletResponse response) throws ServletException, IOException {
    RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/AMLManagement.jsp");
    request.setAttribute("items", find("id"));
    dispatcher.forward(request, response);
}

我收到了错误Severe: WebModule[/MavenProjectTest]StandardWrapper.Throwable org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.

还有这个:Severe: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.

有人知道如何解决这个问题吗?我在上面的代码中做错了什么导致了这个错误吗?

【问题讨论】:

  • 还有更多的堆栈跟踪吗?还有什么让您认为您发布的代码与它有任何关系?
  • @peeskillet 我在添加此代码后立即收到此错误,我之前没有问题
  • 对于find 方法,您不需要@Path 吗?
  • @asgs 我不知道,我在我的 findAll 上做了同样的事情,但是我有一个“@override”,但这对这个不起作用,我没有知道为什么

标签: java rest maven jsp jax-rs


【解决方案1】:

好的,我必须添加一个路径,我传递的 id 不应该是一个字符串,我必须在 findId 中添加一个@Pathparam,我是这样解决的:

@GET
@Path("{id}")
@Produces({"application/xml", "application/json"})
public WatchList find(@PathParam("id") Integer id) {
    WatchList results = em.createNamedQuery("WatchList.findById", WatchList.class)
            .setParameter("id", id)
            .getSingleResult();
    return results;
}

@GET
@Path("{id}")
@Produces(MediaType.TEXT_HTML)
public void findId(@PathParam("id") Integer id,
        @Context final HttpServletRequest request,
        @Context final HttpServletResponse response) throws ServletException, IOException {
    RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/AMLManagement.jsp");
    request.setAttribute("items", find(id));
    dispatcher.forward(request, response);
}

【讨论】:

    猜你喜欢
    • 2015-10-25
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 2016-04-21
    相关资源
    最近更新 更多