当前位置: 首页 > 知识库问答 >
问题:

尝试使用JAXRS重新恢复Web服务时抛出异常

太叔灿
2023-03-14

我开发了一个RestEasy Hello World示例,用于自我评估,但当我尝试使用JBOSS7运行此项目时。0我看到下面提到的错误的打印堆栈跟踪:请向我建议可能的解决方案,或者如果我在上述xml和java文件中编码错误,请告诉我。

 12:54:44,145 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/resteasy]] (MSC service thread 1-6) Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
    at org.scannotation.WarUrlFinder.findWebInfClassesPath(WarUrlFinder.java:56) [scannotation-1.0.3.jar:]
    at org.jboss.resteasy.plugins.server.servlet.ListenerBootstrap.getScanningUrls(ListenerBootstrap.java:64) [resteasy-jaxrs-2.2.1.GA.jar:]
    at org.jboss.resteasy.plugins.server.servlet.ConfigurationBootstrap.createDeployment(ConfigurationBootstrap.java:147) [resteasy-jaxrs-2.2.1.GA.jar:]
    at org.jboss.resteasy.plugins.server.servlet.ListenerBootstrap.createDeployment(ListenerBootstrap.java:32) [resteasy-jaxrs-2.2.1.GA.jar:]
    at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:27) [resteasy-jaxrs-2.2.1.GA.jar:]
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.0.Final.jar:7.0.0.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
    at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_18]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_18]
    at java.lang.Thread.run(Thread.java:619) [:1.6.0_18]
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext from [Module "org.scannotation.scannotation:main" from local module loader @a9c09e (roots: D:\jboss-as-web-7.0.0.Final\modules)]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:358)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:307)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:101)

12:54:44,175 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-6) Context [/resteasy] startup failed due to previous errors
12:54:44,183 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/resteasy]] (MSC service thread 1-6) Exception sending context destroyed event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap: java.lang.NullPointerException
    at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextDestroyed(ResteasyBootstrap.java:37) [resteasy-jaxrs-2.2.1.GA.jar:]
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:3465) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java:3970) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3888) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.0.Final.jar:7.0.0.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)
    at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_18]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_18]
    at java.lang.Thread.run(Thread.java:619) [:1.6.0_18]

下面是我写的程序

马文-

  <repositories>
    <repository>
      <id>org.jboss.resteasy</id>
      <url>http://repository.jboss.org/maven2/</url>
    </repository>
    </repositories>

  <dependencies>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>

     <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>3.0.1.Final</version>
</dependency>

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <version>2.0-beta-2</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jettison-provider</artifactId>
        <version>2.0-beta-2</version>
    </dependency>

    <dependency>
    <groupId>org.jboss.spec.javax.servlet</groupId>
    <artifactId>jboss-servlet-api_3.0_spec</artifactId>
    <version>1.0.0.Final</version>
</dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    </plugins>
    <finalName>resteasy</finalName>
  </build>
</project>

网状物xml

<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Restful Web Application</display-name>

    <!-- Auto scan REST service -->
    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>
    </context-param>

    <!-- this need same with resteasy servlet url-pattern -->
    <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/rest</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

信息驱动。JAVA

package com.sandeep.resteasy;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/message")
public class MessageDriven {

    @GET
    @Path("/{param}")
    public Response printMessage(@PathParam("param") String msg) {

        String result = "Restful example : " + msg;

        return Response.status(200).entity(result).build();

    }

}

共有1个答案

赵同
2023-03-14

您需要删除自动扫描上下文参数

<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>true</param-value>
</context-param>

JBoss AS7自动扫描并添加resteasy。在AS7下运行时,扫描上下文参数将导致此错误。

 类似资料:
  • 前几天,我在我们的一个项目中看到一些代码,它们使用try-catch并重新抛出捕获的异常,如下所示: 除了catch块中的异常之外,没有做任何其他操作,所以我甚至不确定它为什么会被抛出。我看不出再次抛出同一个异常并对该异常不做任何处理有什么好处。 如果重新抛出catch块中捕获的异常,C#如何处理?它是否陷入了无限抛接球循环?还是说它最终会放弃试一试?

  • 当我尝试使用jersy api连接jaserper服务器时,抛出异常java.lang.NoSuchMethodError:org.glassfish.hk2.utilities.AbstractActiveDescriptor 下面是代码 我得到的确切异常如下 线程“main”Java . lang . nosuchmethoderror:org . glassfish . hk2 . util

  • 你怎么捕获一个异常,之后在另外一个线程上重新抛出?使用在标准文档18.8.5中描述的异常传递中的方法吧,那将显示标准库的魔力。 exception_ptr current_exception(); 返回一个exception_ptr 变量,它将指向现在正在处理的异常(15.3)或者现在正在处理的异常的副本(拷贝),或者有的时候在当前没有遇到异常的时候,返回值为一个空的exception_ptr变量

  • 问题内容: 我收到一个错误,指示缺少in 。这是我的网络服务代码: 这是我的: 添加应用程序类无效: 我仍然收到此错误: UPDATE2: 现在我从浏览器执行GET请求时收到此错误 问题答案: 用(或其他字符串)注释您的班级。

  • 您好,我正试图在JBoss developer studio和Wildfly 11上构建一个简单的JaxRs web服务作为应用程序服务器,但我在尝试部署maven项目时遇到以下错误:

  • 假设我有以下功能: 根据Jest文档,我应该能够使用以下代码测试函数是否引发异常: 但是,我得到了以下错误。 有人能告诉我我做错了什么吗? 谢谢!