我正在尝试使用 Tomcat 8.5 上托管的 Jersey 2 项目进行准系统 Swagger 设置。我首先使用 Jersey 入门指南(https://jersey.github.io/documentation/latest/getting-started.html)中的以下代码片段生成了 jersey 项目:
mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-webapp
-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false
-DgroupId=com.example -DartifactId=simple-service-webapp -Dpackage=com.example \
-DarchetypeVersion=2.27
Run Code Online (Sandbox Code Playgroud)
然后我从 swagger 入门指南添加了 Swagger 依赖项(https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Getting-started):
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2-servlet-initializer</artifactId>
<version>2.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当点击http://localhost:8080/simple-service-webapp/webapi/myresource上的 api 时,我得到了正确的响应。当我点击http://localhost:8080/simple-service-webapp/webapi/openapi.json时,我收到 404 Not Found。
有任何想法吗?
这是我的 pom 的样子:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>simple-service-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple-service-webapp</name>
<build>
<finalName>simple-service-webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins> …Run Code Online (Sandbox Code Playgroud)