com.sun.jersey.api.container.ContainerException:ResourceConfig实例不包含任何根资源类。仍然没有运行

时间:2018-09-18 14:46:49

标签: java rest api jersey

我在stackoverflow中遵循了许多解决方案,但是我的其余Web服务仍然出现错误500。ResourceConfig实例不包含任何根资源类。 我的web.xml

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

   <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.carmonitoring</param-value>
   </init-param>
        <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
   <servlet-name>Jersey REST Service</servlet-name>
      <url-pattern>/*</url-pattern>
    </servlet-mapping>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list> 
 </web-app>

我的Java代码是

package com.carmonitoring.resource;

import javax.xml.bind.annotation.XmlRootElement;

import com.carmonitoring.model.Car;

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

@Path("/cars")
@XmlRootElement
public class CarImpl implements CarService{

    @Override
    @GET
    @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
    public Car getDummt() {
        // TODO Auto-generated method stub
        Car car = new Car();
        car.setCarid(1);
        car.setManufacturer("Toyota");
        car.setName("Fortuner");
        car.setModel("2016");
       return car;
   }
}

这是我的PS

enter image description here  我找不到问题在哪里,请帮助我

0 个答案:

没有答案
相关问题