adrianbk / swagger-springmvc-demo

swagger-springmvc-demo
155 stars 103 forks source link

Swagger2 config class not loaded in spring mvc #23

Open adorearun opened 8 years ago

adorearun commented 8 years ago

I am working on setting up swagger2 documentation for my Spring REST Project. But when I try to execute http://localhost:8085/swagger-ui.html returns empty page.The problem is my bean class is not loaded by my spring MVC application and it is NOT a spring boot application.

The below is my swagger2 config class

@Configuration @EnableSwagger2 @EnableWebMvc public class SwaggerConfig extends WebMvcConfigurerAdapter{

@Bean
public Docket newsApi() {
    System.out.println("!@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@22");
return new Docket(DocumentationType.SWAGGER_2)
.groupName("Dialr")
.apiInfo(apiInfo())
.select()
.paths(regex("/*.*"))
.build();
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring REST Sample with Swagger")
.description("Spring REST Sample with Swagger")
.termsOfServiceUrl("http://www-03.ibm.com/software/sla/sladb.nsf/sla/bm?Open")
.contact("Niklas Heidloff")
.license("Apache License Version 2.0")
.licenseUrl("https://github.com/IBM-Bluemix/news-aggregator/blob/master/LICENSE")
.version("2.0")
.build();
}

} The below is my rest-servlet.xml under WEB-INF

<?xml version="1.0" encoding="UTF-8"?>

context:annotation-config/

Please find the web.xml entry as well

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

rest org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/spring/rest-servlet.xml 1

Please let me know if anything is missing ? Any help is highly appreciated.

adorearun commented 8 years ago

please refer below question for better understanding of my problem . http://stackoverflow.com/questions/34388835/swagger2-config-class-not-loaded-in-spring-mvc