How to use Swagger with Jersey in Spring?

I am trying to use Swagger (2.6) with Jersey (1.5) in SpringBoot (1.5.8)

My calls to my public API work fine http: // localhost: 57116 / rest / customer / list

When I load the site http: // localhost: 57116 / swagger-ui.html , it displays Swagger with a lot of default APIs, but it does not display my API, enter image description here

I tried following this Config Swagger-ui with Jersey , but it still is not coming back.

This is my JerseyConfig

@Configuration
@ApplicationPath("rest")
public class JerseyConfig extends ResourceConfig {

public JerseyConfig()
{
    register(CustomerImpl.class);
    configureSwagger();
}
public void configureSwagger()
{
    this.register(ApiListingResource.class);
    this.register(SwaggerSerializers.class);
    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setTitle("Swagger sample app");
    beanConfig.setVersion("1.0.0");
    beanConfig.setSchemes(new String[]{"http"});
    beanConfig.setHost("localhost:57116");
    beanConfig.setBasePath("/rest");
    beanConfig.setResourcePackage("com.mypackage");
    beanConfig.setScan(true);
}
}

This is my application class.

@SpringBootApplication
@EnableDiscoveryClient
@EnableSwagger2
public class CustomerApplication {...}

This is my end point

@Component
@Path("customer")
@Api(value = "Customer API")
public class CustomerImpl {
    @Path("list")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "list")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Success", response = List.class),
            @ApiResponse(code = 401, message = "Unauthorized"),
            @ApiResponse(code = 403, message = "Forbidden"),
            @ApiResponse(code = 404, message = "Not Found"),
            @ApiResponse(code = 500, message = "Failure")})
    public String[] getList()
    {
        return new String[]{"IBM", "Microsoft", "Victor"};
    }
}

When I try to use a similar configuration using Spring RestController, it works fine, but with Jersey I don't see my public API. It seems that I am ignoring the Swagger configuration

+4
1

org.springframework.boot:spring-boot-starter-jersey org.springframework.boot:spring-boot-starter-web pom.xml?

, Swagger bean, SpringFox, BeanConfig.

Swagger , spring-boot-starter-jersey SpringFox, @EnableSwagger2.

swagger.json io.swagger:swagger-jersey2-jaxrs. Swagger, vanilla Swagger UI.

BeanConfig . :

beanConfig.setResourcePackage("io.swagger.resources");

example Spring Boot, Jersey Swagger. :

beanConfig.setResourcePackage("com.basaki");
+3

Source: https://habr.com/ru/post/1689836/


All Articles