【问题标题】:web service tutorial sample on weblogic --> 404weblogic 上的 web 服务教程示例 --> 404
【发布时间】:2017-07-28 01:36:06
【问题描述】:

我已按照 web 服务教程示例并部署在 weblogic 上。但是当我输入网址时,它显示 404。我有什么错误或遗漏吗? 我的路径是http://localhost:7001/aeon_mobileapps_java_ws/UserService/users

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
    <servlet>
        <display-name>My Jersey Application</display-name>
        <servlet-name>MyJerseyApp</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.tutorialspoint</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyJerseyApp</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

weblogic.xml

<?xml version='1.0' encoding='UTF-8'?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<library-ref>
    <library-name>jax-rs</library-name>
    <specification-version>1.1</specification-version>
    <implementation-version>1.9</implementation-version>
    <exact-match>false</exact-match>
</library-ref>
</weblogic-web-app>

pom.xml

<dependencies>
  <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-server -->
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.19.4</version>
</dependency>
  <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-core -->
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-core</artifactId>
    <version>1.19.4</version>
</dependency>
  <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-bundle -->
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-bundle</artifactId>
    <version>1.19.4</version>
</dependency>
  <!-- https://mvnrepository.com/artifact/asm/asm -->
<dependency>
    <groupId>asm</groupId>
    <artifactId>asm</artifactId>
    <version>3.3.1</version>
</dependency>
  <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

  </dependencies>

the url path and my project structure screen

【问题讨论】:

    标签: java json xml rest maven


    【解决方案1】:

    404 错误是因为找不到页面或错误的 url。您正在使用球衣休息服务,因此您需要使用控制器和方法的路径映射。您需要在类和方法之前使用@Path 注释。

    您可以找到以下示例代码:

    @Path("/test")  
    public class Test{  
    
    @GET  
    @Path("/{text}")  
    public Response getText(@PathParam("text") String text) {  
        String output = text;  
        return Response.status(200).entity(output).build();  
    }  
    

    所以如果不检查你的代码不能给出正确的答案,我只是说错误的可能原因。

    【讨论】:

    • 包 com.tutorialspoint;导入 java.util.List;导入 javax.ws.rs.GET;导入 javax.ws.rs.Path;导入 javax.ws.rs.Produces;导入 javax.ws.rs.core.MediaType; @Path("/UserService") public class UserService { UserDao userDao = new UserDao(); @GET @Path("/users") @Produces(MediaType.APPLICATION_XML) public List getUsers(){ return userDao.getAllUsers(); } }
    猜你喜欢
    • 1970-01-01
    • 2014-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    • 1970-01-01
    • 2014-06-06
    相关资源
    最近更新 更多