我使用IBM WebSphere Application Server V7开发了RESTful Web服务(JAX-RS),并在执行url:“ http://localhost:9080/Conference/resources/Conference/”时,启动了例外的Error 404: SRVE0190E: File not found : /resources/Conference,与url“ http://localhost:9080/Conference/resources/Conference/1”相同。
这是3个类和web.wml文件:

Conference.java

package co.ma.jaxrs;
public class Conference {
        public final String name;
        public final String date;
        public final String url;

        public Conference(String name, String date, String url) {
            super();
            this.name = name;
            this.date = date;
            this.url = url;
        }
    }


ConferenceRessource.java

package co.ma.jaxrs;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/Conference")
public class ConferenceRessource {

    private static List<Conference> conferences = new ArrayList<Conference>();
    static {
        conferences.add(new Conference("Nom 1 ", "Mardi 12 Novembre",
                "http://google.com"));
        conferences.add(new Conference("Nom 2 ", "Jeudi 1 Octobre",
                "http://youtube.com"));
        conferences.add(new Conference("Nom 3 ", "Lundi 5 Janvier",
                "http://facebook.com"));
    };

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public List<Conference> getList() {
        return conferences;
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("{id}")
    public Conference getConferenceById(@PathParam("id") int id) {
        return conferences.get(id);
    }
}


TestApplication.java

package co.ma.jaxrs;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("resources")
public class TestApplication extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(ConferenceRessource.class);
        return classes;
    }

}


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_2_5.xsd" version="2.5">
    <display-name>Conference</display-name>
    <servlet>
        <description>
        JAX-RS Tools Generated - Do not modify</description>
        <servlet-name>JAX-RS Servlet</servlet-name>
        <servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
</web-app>

最佳答案

如下所示在TestApplication.java中公开测试资源,并检查是否可以访问它

`
@ApplicationPath("resources")
public class TestApplication extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(ConferenceRessource.class);
        return classes;
    }

@Path("/test")
public void printDebug(){
    System.out.println("got debug here");
}

}`


网址:http://localhost:9080/Conference/resources/test

07-24 19:54