How to enable Swagger UI? Tomcat, SpringMVC, REST
The trick is that your swagger-ui maven dependency is a webjar. You need to configure the path from your webserver to the webjar.
I used the current maven dependency:
<dependency> <groupId>org.webjars</groupId> <artifactId>swagger-ui</artifactId> <version>2.1.3</version></dependency>
And configured it with annotations:
@Configuration@EnableWebMvcpublic class RestConfiguration extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/2.1.3/"); }// [...]}
Same can be done with with xml in your spring configuration:
<mvc:resources mapping="/swagger-ui/**" location="classpath:/META-INF/resources/webjars/swagger-ui/2.1.3/"/>
Also see: http://www.jamesward.com/2012/04/30/webjars-in-spring-mvc
I solved my problem by adding swagger-ui resources to
src\main\webapp\docs
I also added
<mvc:default-servlet-handler/>
To pom.xml
Now I can access swagger UI under:
http://localhost:8080/myapp/docs/