Skip to content

Commit

Permalink
Merge branch 'fix-vanilla-java'
Browse files Browse the repository at this point in the history
  • Loading branch information
dilipkrish committed Jul 5, 2020
2 parents 9590c10 + cba3c4e commit f5a9b07
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
8 changes: 5 additions & 3 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ ext {
"org.springframework:spring-core:$springVersion",
"org.springframework:spring-web:$springVersion",
"org.springframework:spring-webmvc:$springVersion"

],
springBoot : [
"org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
],

springfoxPetstore : [
"io.springfox:springfox-petstore:2.10.5"
],
Expand All @@ -26,9 +24,13 @@ ext {
"io.springfox:springfox-spring-webmvc:${springfoxVersion}",
"io.springfox:springfox-swagger2:${springfoxVersion}"
],
springfoxOpenApi : [
"io.springfox:springfox-spring-web:${springfoxVersion}",
"io.springfox:springfox-spring-webmvc:${springfoxVersion}",
"io.springfox:springfox-oas:${springfoxVersion}"
],
springfoxSwaggerUi: [
"io.springfox:springfox-swagger-ui:${springfoxVersion}"
// "io.springfox.ui:springfox-swagger-ui-rfc6570:1.0.0"
],
jackson : [
"com.fasterxml.jackson.core:jackson-core:${jacksonVersion}",
Expand Down
2 changes: 1 addition & 1 deletion spring-java-swagger/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'war'
dependencies {
compile libs.spring
compile libs.jackson
compile libs.springfoxSwagger2
compile libs.springfoxOpenApi
compile libs.springfoxSwaggerUi
compile 'org.slf4j:slf4j-simple:1.7.30'
testCompile libs.test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
import springfox.documentation.oas.annotations.EnableOpenApi;

@Configuration
@ComponentScan
@EnableWebMvc
@EnableSwagger2WebMvc
public class ApplicationConfiguration {
@ComponentScan("springfoxdemo.java.swagger")
@EnableOpenApi
public class AppConfiguration {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{ApplicationConfiguration.class};
}
public class ServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{SpringConfig.class};
return new Class[] { AppConfiguration.class };
}

@Override
protected String[] getServletMappings() {
return new String[]{"/*"};
return new String[] { "/" };
}

@Override
protected Class<?>[] getRootConfigClasses() {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package springfoxdemo.java.swagger;

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Component
public class SpringConfig implements WebMvcConfigurer {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.
addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
.resourceChain(false);
}

registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/swagger-ui/")
.setViewName("forward:" + "/swagger-ui/index.html");
}
}

0 comments on commit f5a9b07

Please sign in to comment.