Swagger 3.0-@ApplicationPath似乎不起作用?
我目前正在安装Swagger,但@ApplicationPath似乎没有按预期工作 我有以下代码:Swagger 3.0-@ApplicationPath似乎不起作用?,swagger,Swagger,我目前正在安装Swagger,但@ApplicationPath似乎没有按预期工作 我有以下代码: @ApplicationPath("/service") @Api( tags = "docs" ) @OpenAPIDefinition(info = @Info( title = "My application", version = "1.0.0", ) public cla
@ApplicationPath("/service")
@Api( tags = "docs" )
@OpenAPIDefinition(info = @Info(
title = "My application",
version = "1.0.0",
)
public class SwaggerApplicationConfig extends Application {
}
在Web.xml中:
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
javax.ws.rs.core.Application
/服务/*
示例端点:
/**
* Customer Endpoints
*/
@Path("/customer")
@Tag(name = "Customer", description = "Returns all information for customers")
public class CustomerWebservice {
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Returns all Customer", notes = "Returns Customer", response = Response.class)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successful, returning the value"),
@ApiResponse(responseCode = "404", description = "Not found"),
@ApiResponse(responseCode = "500", description = "Internal Server Error")
})
public Response findAllCustomers() {
try {
return Response.ok(customerDtoList, MediaType.APPLICATION_JSON)
.build();
} catch (Exception e) {
LOGGER.error(ExceptionUtils.getFullStackTrace(e));
ErrorMessage errorMessage = new ErrorMessage(e.getMessage(), Status.INTERNAL_SERVER_ERROR.getStatusCode());
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(errorMessage).type(MediaType.APPLICATION_JSON)
.build();
}
}
I´m using those libs:
`<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2</artifactId>
<version>2.1.8</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-jaxrs2-servlet-initializer-v2</artifactId>
<version>2.1.8</version>
</dependency>
/**
*客户端点
*/
@路径(“/customer”)
@标签(name=“Customer”,description=“返回客户的所有信息”)
公共类CustomerWebservice{
@得到
@路径(“/”)
@产生(MediaType.APPLICATION_JSON)
@ApiOperation(value=“返回所有客户”,notes=“返回客户”,response=response.class)
@ApiResponses(值={
@ApiResponse(responseCode=“200”,description=“成功,返回值”),
@ApiResponse(responseCode=“404”,description=“未找到”),
@ApiResponse(responseCode=“500”,description=“内部服务器错误”)
})
公众响应findAllCustomers(){
试一试{
返回Response.ok(customerDtoList,MediaType.APPLICATION_JSON)
.build();
}捕获(例外e){
LOGGER.error(ExceptionUtils.getFullStackTrace(e));
ErrorMessage ErrorMessage=新的ErrorMessage(例如getMessage(),Status.INTERNAL_SERVER_ERROR.getStatusCode());
返回Response.status(status.INTERNAL\u SERVER\u ERROR).entity(errorMessage).type(MediaType.APPLICATION\u JSON)
.build();
}
}
我正在使用这些LIB:
`
io.swagger.core.v3
斯威格-jaxrs2
2.1.8
io.swagger.core.v3
swagger-jaxrs2-servlet-initializer-v2
2.1.8
生成了json文件,但URL仅为:
http://localhost:8080/customer
但它应该是:
http://localhost:8080/service/customer
在“大摇大摆”GUI中:
你知道什么需要改变吗