You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's a setup of Swagger with Spring MVC without Spring Boot. Note that Swagger had its static resources in a different folder in previous versions (before version 3.0.0).
importorg.springframework.context.annotation.Bean;
importorg.springframework.context.annotation.Configuration;
importspringfox.documentation.builders.RequestHandlerSelectors;
importspringfox.documentation.spi.DocumentationType;
importspringfox.documentation.spring.web.plugins.Docket;
importspringfox.documentation.swagger2.annotations.EnableSwagger2;
importstaticspringfox.documentation.builders.PathSelectors.ant;
@Configuration// Too much to dig through the code if we go w/o this annotation - it does package-scan and imports other// contexts that do package-scan too. On top of that there's an auto-configuration which depends on the// presence of other entities. It's just ugh, you can't easily figure out what's actually initialized.// Kids, don't write libraries like Swagger team - code must be simple and explicit!@EnableSwagger2classSwaggerConfig {
/** * Swagger creates an endpoint that returns JSON with all the info about our API that it deduced from * SpringMVC. This doesn't yet handle HTML/CSS/JS resources though - we set up Spring MVC to handle them. */@BeanDocketswagger() {
returnnewDocket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(ant("/api/**"))
.build();
}
}
Spring MVC context (XML)
And finally we want to import that SwaggerConfig and handle Swagger UI (the HTML/CSS/JS files):
<!-- Swagger keeps HTML/CSS/JS resources in its jar file in META-INF folder. swagger-ui/ is the default context path where Swagger API resides. -->
<mvc:resourcesmapping="/swagger-ui/**"location="classpath:/META-INF/resources/webjars/springfox-swagger-ui/"/>
<context:component-scanbase-package="io.elsci.moleve.web" />
The text was updated successfully, but these errors were encountered:
Here's a setup of Swagger with Spring MVC without Spring Boot. Note that Swagger had its static resources in a different folder in previous versions (before version 3.0.0).
Maven
Serving Swagger requests right from our app
Spring MVC context (XML)
And finally we want to import that SwaggerConfig and handle Swagger UI (the HTML/CSS/JS files):
The text was updated successfully, but these errors were encountered: