我已经做了一个基本的CRUD应用程序,希望添加Swagger与它。
我的端点是-
@RequestMapping(value = "/api/v1")
GET - /get_all_bookings
POST - /new_booking
PUT - /update_booking/{id}
DELETE - /delete_booking/{id}
所以我包含了依赖springfox-swagger2
&springfox-swagger-ui
,然后是一个配置包,里面是SwaggerConfig
类
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket postsApi() {
return new Docket(DocumentationType.SWAGGER_2).groupName("public-api")
.apiInfo(apiInfo()).select().paths(postPaths()).build();
}
private Predicate<String> postPaths() {
return or(regex("/api/v1/*"), regex("/api/v1/get_all_bookings*"));
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("Demo API")
.description("Placeholder")
.termsOfServiceUrl("www.something.com")
.contact("sandeep.roy2014@gmail.com").license("Free")
.licenseUrl("www.somthing.com").version("1").build();
}
}
它给出了太多的错误,我无法理解。
Error creating bean with name 'swagger2Controller': Lookup method resolution failed
Failed to introspect Class [springfox.documentation.swagger2.web.Swagger2Controller] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@2aae9190]
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest
我不太确定,我到底做错了什么!尽管在Postman.
中尝试时所有端点都工作正常。确保您的POM文件中有此依赖项
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>