严重:StandardWrapper.Throwable 在 jax-rs maven 项目中
SEVERE: StandardWrapper.Throwable in jax-rs maven project
添加以下代码后:
@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.
有人知道如何解决这个问题吗?我在上面的代码中做错了什么导致了这个错误吗?
好吧,我必须添加一个路径,我传递的 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);
}
添加以下代码后:
@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.
有人知道如何解决这个问题吗?我在上面的代码中做错了什么导致了这个错误吗?
好吧,我必须添加一个路径,我传递的 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);
}