简单RESTtful Web服务实现中的错误 [英] error in simple RESTtful web service implementation

查看:97
本文介绍了简单RESTtful Web服务实现中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用的软件

Java版本: 1.7.0_21;

Eclipse版本:开普勒

应用程序服务器:wildfly-8.1.0.Final(带有RESTeasy捆绑包)

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

我的尝试

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

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 是我在阅读后创建的来源: [1] [2] > [3]

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

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

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)?

推荐答案

我下载了 JBoss快速入门指南,并观察到 hellowrld-rs 示例。它是 web.xml ,其配置如下所示:

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>

然后我注意到我之前引用的资源是针对较老的JBoss(6/7)的指南,而不是WildFly

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

这篇关于简单RESTtful Web服务实现中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆