【问题标题】:Error 404: SRVE0190E: File not found , RESTful Web Services (JAX-RS)错误 404:SRVE0190E:找不到文件,RESTful Web 服务 (JAX-RS)
【发布时间】:2018-04-12 10:42:02
【问题描述】:

我使用 IBM WebSphere Application Server V7 开发了一个 RESTful Web Services (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>

【问题讨论】:

  • 您能否将您的日志输出从服务器启动发布到您看到 404 的位置?上下文根可能与您的预期不同,或者日志中存在一些部署错误/警告,可能会提示出现问题。
  • 从 web.xml 中删除条目。您可以通过 web.xml 或通过带有 @ApplicationPath 注释的类来配置 JAX-RS。两者都不是。

标签: java rest jax-rs websphere-7


【解决方案1】:

在 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

【讨论】:

    猜你喜欢
    • 2013-06-26
    • 1970-01-01
    • 2017-02-07
    • 2019-09-23
    • 1970-01-01
    • 2011-03-02
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多