我不知道我做错了什么。我们之前在 Jersey JAX-RS 项目中使用了 swagger-core 来生成 swagger.json。它影响了我们的性能,然后我们发现了 swagger-maven-plugin,它只会在编译时而不是运行时生成 swagger.json。所以我尝试过渡到 swagger-maven-plugin。我希望我理解这一点是正确的。我离开了 web.xml,因为它在 swagger-core 配置和 maven 依赖项期间也是如此,但是将插件添加到相同的构建中,如下所示:pom.xml
<profile>
<id>daily</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<resources.directory>${basedir}/src/daily/resources
</resources.directory>
<resources.test.directory>${basedir}/src/test/daily/resources
</resources.test.directory>
<config.directory>${basedir}/src/daily/config</config.directory>
<env.base.dir>${project.build.directory}/etc</env.base.dir>
</properties>
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey-jaxrs</artifactId>
<version>1.5.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<apiSources>
<apiSource>
<springmvc>false</springmvc>
<locations>
<location>api.resource</location>
<location>api.model.datagov</location>
<location>api.model.eventitem</location>
<location>api.model.item</location>
</locations>
<schemes><scheme>http</scheme></schemes>
<basePath>/itemapi</basePath>
<info>
<title>ItemAPI</title>
<version>0.0.1-SNAPSHOT</version>
</info>
<outputPath>${basedir}/src/main/webapp/output.html</outputPath>
<swaggerDirectory>${basedir}/src/main/webapp/dist</swaggerDirectory>
<attachSwaggerArtifact>true</attachSwaggerArtifact>
</apiSource>
</apiSources>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<resources>
<resource>
<directory>${basedir}/src/daily/resources</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${basedir}/src/test/daily/resources</directory>
</testResource>
<testResource>
<directory>${basedir}/src/test/resources</directory>
</testResource>
</testResources>
</build>
</profile>
我不得不添加 pluginManagement 标记,因为执行标记给出了错误。顺便说一句,我在 eclipse 中做所有这些。
这是 web.xml 中的招摇配置,以防万一:
<servlet>
<servlet-name>JAX-RS Servlet</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>
io.swagger.jaxrs.listing;
io.swagger.jaxrs.json;
org.codehaus.jackson.jaxrs;
api.resource
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/itemapi/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Jersey2Config</servlet-name>
<servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>0.0.1-SNAPSHOT</param-value>
</init-param>
<init-param>
<param-name>swagger.api.title</param-name>
<param-value>ItemApi</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>/itemapi/</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
现在,我右键单击项目并选择 maven -> build -> clean install,它构建成功,但在 webapp 文件夹下我没有看到任何 output.html 或在“dist”文件夹中没有 swagger.json。我什至尝试通过 cmd 进入 git 项目,然后运行 mvn compile。相同的。建立成功,但实际上什么也没发生。我究竟做错了什么?