我想尝试将Swagger添加到我的RESTeasy应用程序。我试着跟随Documentation,但我无法到达 Swagger 的终点。我得到的是一个错误404。
我的技术堆栈:
- Tomcat 10.0.1
- Java 17
我的目标:
- 我想在http://localhost:8080/sample/openapi下访问我的nice API文档
openapi: "3.0.3"
info:
title: "My API2"
version: "1.0"
servers:
- url: "http://localhost:8080/"
paths:
字符串
openapi.yaml在src/main/resources
@ApplicationPath("/api")
public class TimeToolRestApplication extends Application {
private Set<Object> singletons = new HashSet<>();
private static final Logger logger = LogManager.getLogger(TimeToolRestApplication.class);
public TimeToolRestApplication() {
singletons.add(new HealthController());
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
型
TimeToolRestApplication.java
@Path("/v1")
public class HealthController {
@GET
@Path("/health")
public Response healthcheck() {
return Response.ok().entity(true).build();
}
}
型
HealthController.java
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<resteasy.version>6.2.4.Final</resteasy.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.15.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-core</artifactId>
<version>${resteasy.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-client -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.2.14</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
<version>2.2.14</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-core-jakarta</artifactId>
<version>2.2.14</version>
</dependency>
</dependencies>
型
pom.xml
我试着跟着Swagger的Documentation走。有和没有初始化器。但似乎什么都不管用
1条答案
按热度按时间35g0bw711#
好的,我现在修好了。我需要做以下事情:
在我的应用程序类中:
字符串
我需要添加这些。我还删除了我的openapi.yaml,并使用初始化器依赖项。如上所述,@James R. Perkins我切换到了-jakarta依赖项。