error in simple RESTtful web service implementation

[亡魂溺海] 提交于 2019-12-11 08:08:46

问题


Softwares used :

Java Version : "1.7.0_21"
Eclipse Version : Kepler
Application Server : wildfly-8.1.0.Final(with RESTeasy bundle)

My try :

I want to implement REST web service. My resources is university.

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 which I created after reading from sources: [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>

Now, I right click on my Project to "Run on Server" but following error comes as

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

Why am I getting ClassNotFoundException error? Do I need to add any extra dependencies in my pom.xml(so far none added because RESTeasy states no extra dependencies requires to be added)?


回答1:


I downloaded JBoss quick-start guide and observed given hellowrld-rs example. It's web.xml which was very minimally configured as given below:

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

I then noted the sources I referenced earlier were guide for older JBoss(6/7) and not WildFly.



来源:https://stackoverflow.com/questions/24308617/error-in-simple-resttful-web-service-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!