加热后我为什么得到http 404 http:// localhost:3636 / RestSwagger / rest / swagger.json

时间:2016-07-28 11:28:31

标签: api rest swagger

    Hi While I am trying to acess swagger.json from my Rest Api    http://localhost:3636/RestSwagger/rest/swagger.json
     why I am getting http 404 as a response.
  Below I am providing my whole code please follow  
    my pom.xml
    ----------

            <dependency>
                <groupId>com.sun.jersey</groupId>
                <artifactId>jersey-server</artifactId>
                <version>1.8</version>
            </dependency>

        <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-jaxrs</artifactId>
                <version>1.5.8</version>
            </dependency>


    my web.xml
    ---------
    <servlet>
            <servlet-name>jersey-serlvet</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.rest.swagger</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
            <servlet-name>jersey-serlvet</servlet-name>
            <url-pattern>/rest/*</url-pattern>
        </servlet-mapping>

        <servlet>
            <servlet-name>SwaggerBootstrap</servlet-name>
            <servlet-class>com.rest.swagger.SwaggerApplication</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>



    my Rest Application
    -------------------

    package com.rest.swagger;

    import io.swagger.annotations.Api;
    import io.swagger.annotations.ApiOperation;
    import io.swagger.annotations.ApiParam;
    import io.swagger.annotations.ApiResponse;
    import io.swagger.annotations.ApiResponses;

    import javax.ws.rs.FormParam;
    import javax.ws.rs.POST;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;
    import javax.ws.rs.core.Response;

    @Path("/customers")
    @Api(value = "/customers", description = "Manage customer")
    public class RestServiceFormParam {

        @POST
        @Path("/addCustomer")
        @Produces("text/html")
        @ApiOperation(value = "Get Customer details from form page", response = RestServiceFormParam.class, 
        responseContainer = "List")
        @ApiResponses({ @ApiResponse(code = 200, message = "Customer Details message with name and country") })
        public Response getResultByPassingValue(
                @ApiParam(value = "Page to fetch name and country", required = true) @FormParam("nameKey") String name,
                @FormParam("countryKey") String country) {

            String output = "<font face='verdana' size='2'>"
                    + "Web Service has added your Customer information with Name - <u>"
                    + name + "</u>, Country - <u>" + country + "</u></font>";
            return Response.status(200).entity(output).build();

        }
    }

my swagger servlet application
--------------------------------

包com.rest.swagger;

import io.swagger.jaxrs.config.BeanConfig;

import javax.servlet.ServletConfig;

  • 列表项

import javax.servlet.ServletException; import javax.servlet.http.HttpServlet;

公共类SwaggerApplication扩展了HttpServlet {

private static final long serialVersionUID = -6039834823506457822L;

@Override
public void init(ServletConfig config) throws ServletException {

    super.init(config);

    BeanConfig beanConfig = new BeanConfig();

    final String contextPath = config.getServletContext().getContextPath();
    final StringBuilder sbBasePath = new StringBuilder();
    sbBasePath.append(contextPath);
    sbBasePath.append("/rest");
    beanConfig.setBasePath(sbBasePath.toString());

    // API Info
    beanConfig.setVersion("0.1");
    beanConfig.setTitle("My Swagger APP");
    beanConfig.setResourcePackage("com.rest.swagger");
    beanConfig.setScan(true);
}

}

0 个答案:

没有答案