在我的项目中,我使用 Maven、Jetty、Swagger、Java 和 Jersey 来创建 REST API。我还使用 Swagger 为我的 API 创建漂亮的文档。
几乎一切都很好,而不是三个问题。一开始 - 这是我的 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
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>Restful Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.pjdb.rest;com.wordnik.swagger.jaxrs;</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8080/rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Bootstrap</servlet-name>
<servlet-class>com.pjdb.rest.Bootstrap</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>ApiOriginFilter</filter-name>
<filter-class>com.pjdb.rest.utils.ApiOriginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ApiOriginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
1)如何从listingPath的开头删除api-docs?
{
"apiVersion": "1.0",
"swaggerVersion": "1.1",
"basePath": "http://localhost:8080/rest",
"apis": [
{
"path": "/api-docs/resources",
"description": ""
},
{
"path": "/api-docs/employee",
"description": ""
}
]
}
我想在路径的开头删除 /api-docs ..
2) 如何从 api 中删除“/api-docs/resources”?我只使用“员工”类,而不是“资源”。
3)如果我输入http://localhost:8080/rest/api-docs/employee
我的方法和'/'主 URL 是空的。我可以删除它吗?
我尝试了很多配置。我错过了什么吗?