Skip to content

Commit

Permalink
initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
otary committed Jul 22, 2019
1 parent 3f3d59c commit 0b0369c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cn.chenzw.swagger.ext.spring.config;

import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SwaggerConfig {
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("cn.chenzw.swagger.ext.spring.samples"))
.apis(RequestHandlerSelectors.basePackage("cn.chenzw.swagger.ext.spring"))
.paths(PathSelectors.any())
.build();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cn.chenzw.swagger.ext.spring.config;

import org.springframework.context.annotation.ComponentScan;
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
@ComponentScan(basePackages = {"cn.chenzw.swagger.ext.spring"})
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(
"classpath:/static/");
// 指定swagger-ui.html页面的路径
registry.addResourceHandler("swagger-ui.html").addResourceLocations(
"classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
super.addResourceHandlers(registry);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cn.chenzw.swagger.ext.spring.initializer;

import cn.chenzw.swagger.ext.spring.config.AppConfig;
import cn.chenzw.swagger.ext.spring.config.WebConfig;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{AppConfig.class};
}

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

@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
spring.profiles.include=swagger

swagger.scan-basepackage=cn.chenzw.swagger.ext.spring.samples
swagger.scan-basepackage=cn.chenzw.swagger.ext.spring
swagger.title=\u6D4B\u8BD5\u9879\u76EEAPI
swagger.description=Swagger API
swagger.term-of-service-url=
Expand Down
4 changes: 3 additions & 1 deletion swagger-ext-samples/swagger-ext-spring-samples/starup.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@echo off

mvn tomcat7:run
mvn tomcat7:run

@rem start chrome.exe http://localhost:8080/swagger-ext-spring-samples/swagger-ui.html

0 comments on commit 0b0369c

Please sign in to comment.