简单的RESTtful Web服务实现中的错误

时间:2014-06-19 14:06:20

标签: java web-services resteasy classnotfoundexception wildfly

使用的软件

Java版本:" 1.7.0_21"
Eclipse版本:开普勒
Application Server:wildfly-8.1.0.Final(使用RESTeasy捆绑包)

我的尝试

我想实现REST Web服务。我的资源是大学。

package com.nagarro.university;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;

@ApplicationPath("/university")  //??? OR @Path("/university")???
public class University extends Application{

    @GET
    @Produces(MediaType.TEXT_HTML)
    public String getHTMLUniversityInfo(){
        return "<html> "
                + "<title>"
                + "University Information"
                + "</title>"
                + "<body>"
                + "<h1>"
                + "NAME- IIIT"
                + "</h1>"
                + "</body>"
                + "</html>";
    }

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getXMLUniversityInfo() {
        return "NAME-IIITA";
    }

    @PUT
    @Path("{studentRollNo}")
    @Produces(MediaType.TEXT_PLAIN)
    public String updateUniversityInfo(@PathParam("studentRollNo") String studentRollNo) {

        // CODE TO UPDATE STUDENT
        return "Done SUccessfully!!!";
    }
}
我从资料来源阅读后创建的

web.xml [1] [2] [3]

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>UniversityRESTful-WS</display-name>

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

    <servlet>
        <servlet-name>Resteasy</servlet-name>
        <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.nagarro.university.University</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Resteasy</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>

现在,我右键单击我的项目到&#34;在服务器上运行&#34;但是跟随错误是

19:12:23,467 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-10) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./UniversityRESTful-WS: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./UniversityRESTful-WS: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_21]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_21]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_21]
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.nagarro.university.University from [Module "deployment.UniversityRESTful-WSEAR.ear.UniversityRESTful-WS.war:main" from Service Module Loader]
    at org.jboss.resteasy.spi.ResteasyDeployment.createApplication(ResteasyDeployment.java:292)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:95)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36)
    at io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:214)
    at io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:119)
    at io.undertow.servlet.core.DeploymentManagerImpl.start(DeploymentManagerImpl.java:505)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:88)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    ... 3 more
Caused by: java.lang.ClassNotFoundException: com.nagarro.university.University from [Module "deployment.UniversityRESTful-WSEAR.ear.UniversityRESTful-WS.war:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules.jar:1.3.3.Final]
    at org.jboss.resteasy.spi.ResteasyDeployment.createApplication(ResteasyDeployment.java:288)
    ... 12 more

19:12:23,473 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "UniversityRESTful-WSEAR.ear")]) - failure description: {"JBAS014671: Failed services" => {"jboss.undertow.deployment.default-server.default-host./UniversityRESTful-WS" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./UniversityRESTful-WS: Failed to start service
    Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.nagarro.university.University from [Module \"deployment.UniversityRESTful-WSEAR.ear.UniversityRESTful-WS.war:main\" from Service Module Loader]
    Caused by: java.lang.ClassNotFoundException: com.nagarro.university.University from [Module \"deployment.UniversityRESTful-WSEAR.ear.UniversityRESTful-WS.war:main\" from Service Module Loader]"}}
19:12:23,839 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "UniversityRESTful-WSEAR.ear" (runtime-name : "UniversityRESTful-WSEAR.ear")
19:12:23,840 INFO  [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.undertow.deployment.default-server.default-host./UniversityRESTful-WS: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./UniversityRESTful-WS: Failed to start service

19:12:23,906 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
19:12:23,907 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
19:12:23,907 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: WildFly 8.1.0.Final "Kenny" started (with errors) in 3239ms - Started 286 of 350 services (3 services failed or missing dependencies, 99 services are lazy, passive or on-demand)
19:12:24,100 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-5) HV000001: Hibernate Validator 5.1.0.Final
19:12:24,143 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) JBAS015974: Stopped subdeployment (runtime-name: UniversityRESTful-WS.war) in 63ms
19:12:24,144 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-9) JBAS015877: Stopped deployment UniversityRESTful-WSEAR.ear (runtime-name: UniversityRESTful-WSEAR.ear) in 65ms
19:12:24,221 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018558: Undeployed "UniversityRESTful-WSEAR.ear" (runtime-name: "UniversityRESTful-WSEAR.ear")
19:12:24,224 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014775:    New missing/unsatisfied dependencies:
      service jboss.deployment.subunit."UniversityRESTful-WSEAR.ear"."UniversityRESTful-WS.war".component."javax.faces.webapp.FacetTag".START (missing) dependents: [service jboss.deployment.subunit."UniversityRESTful-WSEAR.ear"."UniversityRESTful-WS.war".deploymentCompleteService] 
      service jboss.deployment.subunit."UniversityRESTful-WSEAR.ear"."UniversityRESTful-WS.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".START (missing) dependents: [service jboss.deployment.subunit."UniversityRESTful-WSEAR.ear"."UniversityRESTful-WS.war".deploymentCompleteService] 
      service jboss.deployment.subunit."UniversityRESTful-WSEAR.ear"."UniversityRESTful-WS.war".component."org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher".START (missing) dependents: [service jboss.deployment.subunit."UniversityRESTful-WSEAR.ear"."UniversityRESTful-WS.war".deploymentCompleteService] 
      service jboss.deployment.subunit."UniversityRESTful-WSEAR.ear"."UniversityRESTful-WS.war".deploymentCompleteService (missing) dependents: [service jboss.deployment.unit."UniversityRESTful-WSEAR.ear".deploymentCompleteService] 
      service jboss.undertow.deployment.default-server.default-host./UniversityRESTful-WS (missing) dependents: [service jboss.deployment.subunit."UniversityRESTful-WSEAR.ear"."UniversityRESTful-WS.war".deploymentCompleteService] 
JBAS014777:   Services which failed to start:      service jboss.undertow.deployment.default-server.default-host./UniversityRESTful-WS

19:12:28,856 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) JBAS015003: Found UniversityRESTful-WSEAR.ear in deployment directory. To trigger deployment create a file called UniversityRESTful-WSEAR.ear.dodeploy

为什么我收到ClassNotFoundException错误?我是否需要在我的pom.xml中添加任何额外的依赖项(到目前为止还没有添加,因为RESTeasy声明不需要添加额外的依赖项)?

1 个答案:

答案 0 :(得分:0)

我下载了JBoss quick-start guide并观察了给定的hellowrld-rs示例。它是web.xml,其配置非常简单,如下所示:

<servlet-mapping>
    <servlet-name>javax.ws.rs.core.Application</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

然后我注意到我之前提到的来源是旧JBoss(6/7)的指南,而不是WildFly。