How do I use Swagger with Jersey in Spring?

Viewed 2534

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 up the http://localhost:57116/swagger-ui.html site, 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 does not come 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 endpoint

@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 a similar config using Spring RestController, it works fine, but with Jersey I don't see my public API. It seems to be ignoring my Swagger configuration

1 Answers
Related