制作第二个休息服务资源

时间:2016-04-15 16:54:48

标签: java web-services rest servlets

我正在努力学习构建其他网络服务,观看Java Brains的视频。我不是仅仅遵循导师的所有内容,而是尝试将其混合起来。因此,当我在新软件包上构建新服务类但仍然收到错误Servlet.init() for servlet Second Jersey REST Service threw exception时,我遇到了这个问题。如果有人解释为什么会很高兴吗?我正在使用netbeans IDE。

这是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>
             com.sun.jersey.spi.container.servlet.ServletContainer
        </servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>com.services.messages</param-value>
    </init-param>


    <load-on-startup>1</load-on-startup>
</servlet>

<!--New Part added -->
<servlet>
    <servlet-name>Second Jersey REST Service</servlet-name>
        <servlet-class>
             com.sun.jersey.spi.container.servlet.ServletContainer
        </servlet-class>
    <init-param>

      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>com.services.profiles</param-value>
    </init-param>


    <load-on-startup>2</load-on-startup>
</servlet>


<servlet-mapping>
  <servlet-name>Jersey REST Service</servlet-name>
  <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

<!--New part added -->
<servlet-mapping>
  <servlet-name>Second Jersey REST Service</servlet-name>
  <url-pattern>/rest2/*</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>NewServlet</servlet-name>
    <servlet-class>com.servlets.myclass.NewServlet</servlet-class>
    <init-param>
        <param-name>Name</param-name>
        <param-value>Value</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>NewServlet</servlet-name>
    <url-pattern>/NewServlet</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

这是我的新网络服务类:

 package com.service.profiles;

 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;



 @Path("/profiles")
 public class ProfileClass {

  public ProfileClass()
  {
  }

  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String getX()
  {
    return "Got it";
  }
}

0 个答案:

没有答案