Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate springfox-swagger2 with jersey in springboot

I am using springboot with jersey as restful API. Now I want to integrate swagger2 into my project but it doesn't work. When I run my application and access http://localhost:8080/swagger-ui.html. I got the swagger web page but no api is showing(see below image). It seems that swagger didn't find my api classes.

enter image description here

Below is the dependencies I added.

compile "io.springfox:springfox-swagger2:2.5.0"
compile 'io.springfox:springfox-swagger-ui:2.5.0'

Below is my application class:

@SpringBootApplication
@EnableSwagger2
@EnableAutoConfiguration
@Configuration
@ComponentScan(value = "com.ticket.api")
public class Application {

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


    @Bean
    public Docket documentation() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.lenovo.ticket.api"))
                .paths(PathSelectors.any())

                .build().pathMapping("/")
                .useDefaultResponseMessages(false);
    }

    @Bean
    UiConfiguration uiConfig() {
        return UiConfiguration.DEFAULT;
    }

}

Below is my jersey config class:

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

    public JerseyConfig(){
        register(Helloworld.class);
    }

}
like image 935
Joey Yi Zhao Avatar asked Nov 15 '25 11:11

Joey Yi Zhao


1 Answers

Jersey isn't supported, please refer to this answer. Given that the answer comes from SpringFox library's author, I'd say the info is solid.

like image 155
Miloš Milivojević Avatar answered Nov 17 '25 10:11

Miloš Milivojević



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!