question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring Boot + Jersery2 + Swagger2 It can't work at the same time

See original GitHub issue

Spring Boot + Jersery2 + Swagger2 It can’t work at the same time

Spring Boot Application run

BootStartInitialization.class

public static void main(String[] args) { SpringApplication.run(BootStartInitialization.class, args); }

@Bean
public ServletRegistrationBean jerseyServlet() {
    ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(), "/api/*");
    registration.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, JerseyConfig.class.getName());
    return registration;
}

Jersey Configuraction

public class JerseyConfig extends ResourceConfig {

public JerseyConfig() {              

    register(io.swagger.jaxrs.listing.ApiListingResource.class);
    register(io.swagger.jaxrs.listing.SwaggerSerializers.class);          
    register(CrossDomainFilter.class);
    register(JacksonFeature.class);
    register(UserController.class);//this my api
}

}

Swagger2 Configuraction

@Configuration @EnableSwagger2 public class Swagger2 {

@Bean
public Docket createRestApi(ServletConfig config) {     
    return new Docket(DocumentationType.SWAGGER_2)
            //.pathProvider(pathProvider)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.controller"))
            .paths(PathSelectors.any())
            .build();
}

private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
            .title("Spring Boot中使用Swagger2构建RESTful APIs")
            .description("施工平台后台API")
            .termsOfServiceUrl("http://www.xxxx.com/")
            .contact("Jonathan")
            .version("1.0")
            .build();
}

API Controller(Resource)

@Component @Controller @RequestMapping(value=“/accounts”) @Path(“/accounts”) @Api(value = “accounts manager”) @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public class UserController {

/**
 * @Fields log slf4j logger
 */
private static Logger logger = LoggerFactory.getLogger(UserController.class);

@POST
@ApiOperation(value = "Add a new user to the store")
public void create(@ApiParam(value = "Account object that needs to be added to the store", required = true) final String userName) {

}

@Path("{userId}")
@GET
@ApiOperation(value = "Get user's Account by userId")
//@RequestMapping(value={"userId"}, method=RequestMethod.GET)
public String get(@ApiParam(value = "get user's account from db.", required = true) @PathParam("userId") final Integer userId) {
    if (userId != null) {
        return userId.toString();
    } else {
        return "userId is be can't null";
    }
}

}

open http://localhost:8080/swagger-ui.html, no display api docment. on found sub api. can’t display http://localhost:8080/accounts/{userId} api document.

It can’t work at the same time

Spring Boot + Jersey + Swagger Not run?

who is this close? why ? this question not solved.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
youkuancommented, Jun 6, 2016

but it is Spring Boot + Swagger2.0 , Not have Jersey, Not is Jersey’s tage.

I want Spring Boot + Jersey +swagger.

3reactions
fehguycommented, Jun 4, 2016
Read more comments on GitHub >

github_iconTop Results From Across the Web

Springfox swagger - no api-docs with spring boot jersey and ...
As of version 2.5.0 springfox only supports spring-mvc controllers. Jax-rs implementations like jersey aren't supported.
Read more >
OpenAPI 3 Library for spring-boot
Automatically generates documentation in JSON/YAML and HTML format APIs. This documentation can be completed by comments using swagger-api ...
Read more >
Setting Up Swagger 2 with a Spring REST API - Baeldung
Learn how to document a Spring REST API using Swagger 2. ... At the same time, the API documentation should be informative, readable, ......
Read more >
Configure Swagger With Jersey and Spring Boot - FrugalisMinds
We are going to configure Swagger With Jersey and Spring Boot. We saw applications are moving towards micro-services architecture. one of ...
Read more >
How to integrate springfox-swagger2 with jersey in springboot ...
As previously answered in this thread, @EnableSwagger2 annotation and springfox dependencies would work if the endpoints are implemented using Spring MVC ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found