diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/SpringMVCServerCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/SpringMVCServerCodegen.java
index 9ee9199bb94..252457758d8 100644
--- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/SpringMVCServerCodegen.java
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/SpringMVCServerCodegen.java
@@ -68,6 +68,8 @@ public class SpringMVCServerCodegen extends JavaClientCodegen implements Codegen
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "WebApplication.java"));
supportingFiles.add(new SupportingFile("webMvcConfiguration.mustache",
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "WebMvcConfiguration.java"));
+ supportingFiles.add(new SupportingFile("swaggerUiConfiguration.mustache",
+ (sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "SwaggerUiConfiguration.java"));
supportingFiles.add(new SupportingFile("swagger.properties",
("src.main.resources").replace(".", java.io.File.separator), "swagger.properties"));
diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom.mustache
index 4339f5dcdf9..fc15f492fdf 100644
--- a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom.mustache
+++ b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/pom.mustache
@@ -183,6 +183,11 @@
springfox-swagger2
${springfox-version}
+
+ io.springfox
+ springfox-swagger-ui
+ ${springfox-version}
+
org.scalatest
diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/swagger.properties b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/swagger.properties
index 2be15be87ee..fdbe5371934 100644
--- a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/swagger.properties
+++ b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/swagger.properties
@@ -1 +1 @@
-springfox.documentation.swagger.v2.path=/swagger.json
\ No newline at end of file
+springfox.documentation.swagger.v2.path=/api-docs
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/swaggerConfig.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/swaggerConfig.mustache
index 2a74b519317..b33ee7fc994 100644
--- a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/swaggerConfig.mustache
+++ b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/swaggerConfig.mustache
@@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
@@ -16,8 +17,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableWebMvc
@EnableSwagger2 //Loads the spring beans required by the framework
@PropertySource("classpath:swagger.properties")
+@Import(SwaggerUiConfiguration.class)
public class SwaggerConfig {
-
@Bean
ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo(
diff --git a/modules/swagger-codegen/src/main/resources/JavaSpringMVC/swaggerUiConfiguration.mustache b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/swaggerUiConfiguration.mustache
new file mode 100644
index 00000000000..652dc310358
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/JavaSpringMVC/swaggerUiConfiguration.mustache
@@ -0,0 +1,46 @@
+package {{configPackage}};
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+
+@Configuration
+@EnableWebMvc
+public class SwaggerUiConfiguration extends WebMvcConfigurerAdapter {
+ private static final String[] SERVLET_RESOURCE_LOCATIONS = { "/" };
+
+ private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
+ "classpath:/META-INF/resources/", "classpath:/resources/",
+ "classpath:/static/", "classpath:/public/" };
+
+ private static final String[] RESOURCE_LOCATIONS;
+ static {
+ RESOURCE_LOCATIONS = new String[CLASSPATH_RESOURCE_LOCATIONS.length
+ + SERVLET_RESOURCE_LOCATIONS.length];
+ System.arraycopy(SERVLET_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS, 0,
+ SERVLET_RESOURCE_LOCATIONS.length);
+ System.arraycopy(CLASSPATH_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS,
+ SERVLET_RESOURCE_LOCATIONS.length, CLASSPATH_RESOURCE_LOCATIONS.length);
+ }
+
+ private static final String[] STATIC_INDEX_HTML_RESOURCES;
+ static {
+ STATIC_INDEX_HTML_RESOURCES = new String[RESOURCE_LOCATIONS.length];
+ for (int i = 0; i < STATIC_INDEX_HTML_RESOURCES.length; i++) {
+ STATIC_INDEX_HTML_RESOURCES[i] = RESOURCE_LOCATIONS[i] + "index.html";
+ }
+ }
+
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ if (!registry.hasMappingForPattern("/webjars/**")) {
+ registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
+ }
+ if (!registry.hasMappingForPattern("/**")) {
+ registry.addResourceHandler("/**").addResourceLocations(RESOURCE_LOCATIONS);
+ }
+ }
+
+}
diff --git a/samples/server/petstore/spring-mvc/pom.xml b/samples/server/petstore/spring-mvc/pom.xml
index a8fcae3a997..5f6ab531f10 100644
--- a/samples/server/petstore/spring-mvc/pom.xml
+++ b/samples/server/petstore/spring-mvc/pom.xml
@@ -183,6 +183,11 @@
springfox-swagger2
${springfox-version}
+
+ io.springfox
+ springfox-swagger-ui
+ ${springfox-version}
+
org.scalatest
diff --git a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/configuration/SwaggerConfig.java b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/configuration/SwaggerConfig.java
index 07aa9ac789c..fb7361aa3f0 100644
--- a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/configuration/SwaggerConfig.java
+++ b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/configuration/SwaggerConfig.java
@@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
@@ -16,8 +17,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableWebMvc
@EnableSwagger2 //Loads the spring beans required by the framework
@PropertySource("classpath:swagger.properties")
+@Import(SwaggerUiConfiguration.class)
public class SwaggerConfig {
-
@Bean
ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo(
diff --git a/samples/server/petstore/spring-mvc/src/main/java/io/swagger/configuration/SwaggerUiConfiguration.java b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/configuration/SwaggerUiConfiguration.java
new file mode 100644
index 00000000000..ff8f366a880
--- /dev/null
+++ b/samples/server/petstore/spring-mvc/src/main/java/io/swagger/configuration/SwaggerUiConfiguration.java
@@ -0,0 +1,46 @@
+package io.swagger.configuration;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+
+@Configuration
+@EnableWebMvc
+public class SwaggerUiConfiguration extends WebMvcConfigurerAdapter {
+ private static final String[] SERVLET_RESOURCE_LOCATIONS = { "/" };
+
+ private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
+ "classpath:/META-INF/resources/", "classpath:/resources/",
+ "classpath:/static/", "classpath:/public/" };
+
+ private static final String[] RESOURCE_LOCATIONS;
+ static {
+ RESOURCE_LOCATIONS = new String[CLASSPATH_RESOURCE_LOCATIONS.length
+ + SERVLET_RESOURCE_LOCATIONS.length];
+ System.arraycopy(SERVLET_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS, 0,
+ SERVLET_RESOURCE_LOCATIONS.length);
+ System.arraycopy(CLASSPATH_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS,
+ SERVLET_RESOURCE_LOCATIONS.length, CLASSPATH_RESOURCE_LOCATIONS.length);
+ }
+
+ private static final String[] STATIC_INDEX_HTML_RESOURCES;
+ static {
+ STATIC_INDEX_HTML_RESOURCES = new String[RESOURCE_LOCATIONS.length];
+ for (int i = 0; i < STATIC_INDEX_HTML_RESOURCES.length; i++) {
+ STATIC_INDEX_HTML_RESOURCES[i] = RESOURCE_LOCATIONS[i] + "index.html";
+ }
+ }
+
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ if (!registry.hasMappingForPattern("/webjars/**")) {
+ registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
+ }
+ if (!registry.hasMappingForPattern("/**")) {
+ registry.addResourceHandler("/**").addResourceLocations(RESOURCE_LOCATIONS);
+ }
+ }
+
+}
diff --git a/samples/server/petstore/spring-mvc/src/main/resources/swagger.properties b/samples/server/petstore/spring-mvc/src/main/resources/swagger.properties
index 2be15be87ee..fdbe5371934 100644
--- a/samples/server/petstore/spring-mvc/src/main/resources/swagger.properties
+++ b/samples/server/petstore/spring-mvc/src/main/resources/swagger.properties
@@ -1 +1 @@
-springfox.documentation.swagger.v2.path=/swagger.json
\ No newline at end of file
+springfox.documentation.swagger.v2.path=/api-docs
\ No newline at end of file