前后端分离
两款更符合前后分离的
swagger-ui
swagger-bootstrap-ui
swagger-mg-ui
封装swagger依赖,方便使用
pom核心依赖
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.open.capacity</groupId>
<artifactId>inner-intergration</artifactId>
<version>2.0.1</version>
</parent>
<artifactId>swagger-spring-boot-starter</artifactId>
<description>API文档支撑</description>
<properties>
<swagger.version>2.9.2</swagger.version>
<swagger.m.version>1.0.6</swagger.m.version>
</properties>
<dependencies>
<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>com.zyplayer</groupId>
<artifactId>swagger-mg-ui</artifactId>
<version>${swagger.m.version}</version>
</dependency>
</dependencies>
</project>
使用方法
<!-- swagger -->
<dependency>
<groupId>com.open.capacity</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
</dependency>
SwaggerConfig 自动形成swagger文档核心代码
以认证中心代码为例
@Component
@Configuration
@EnableSwagger2
public class SwaggerConfig implements WebMvcConfigurer {
@Bean
public Docket createRestApi() {
ParameterBuilder tokenPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<>();
tokenPar.name("Authorization").description("令牌").
modelRef(new ModelRef("string")).
parameterType("header").required(false).build();
ParameterBuilder clientPar = new ParameterBuilder();
clientPar.name("client_id").description("应用ID").
modelRef(new ModelRef("string")).
parameterType("header").required(false).build();
ParameterBuilder secretPar = new ParameterBuilder();
secretPar.name("client_secret").description("应用密钥").
modelRef(new ModelRef("string")).
parameterType("header").required(false).build();
pars.add(tokenPar.build());
pars.add(clientPar.build());
pars.add(secretPar.build());
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
// .apis(RequestHandlerSelectors.basePackage("com.open.capacity"))
.apis(RequestHandlerSelectors.any())
.paths( input ->
PathSelectors.regex("/oauth/client.*").apply(input) ||
PathSelectors.regex("/oauth/user.*").apply(input) ||
PathSelectors.regex("/oauth/get.*").apply(input) ||
PathSelectors.regex("/oauth/userinfo.*").apply(input) ||
PathSelectors.regex("/oauth/remove.*").apply(input) ||
PathSelectors.regex("/oauth/refresh/token.*").apply(input)||
PathSelectors.regex("/oauth/token/list.*").apply(input)||
PathSelectors.regex("/clients.*").apply(input)||
PathSelectors.regex("/services.*").apply(input)||
PathSelectors.regex("/redis.*").apply(input)
)
// .paths(PathSelectors.any())
.build().globalOperationParameters(pars);
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("认证中心swagger接口文档").description("认证中心swagger接口文档").version("1.0").build();
}
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setViewClass(JstlView.class);
resolver.setPrefix("/");
resolver.setSuffix(".html");
return resolver;
}
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
return messageSource;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// super.addResourceHandlers(registry);
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
访问网关swagger-ui
http://127.0.0.1:9200/swagger-ui.html
访问认证中心swagger-ui
http://127.0.0.1:8000/doc.html(http://127.0.0.1:8000/api-auth/doc.html)
注意查看认证中心代码
如果有上下文路径
## 接口地址 http://127.0.0.1:8000/api-auth/doc.html
访问用户中心swagger-ui
企业微服务开放平台 ,历经多家公司生产考验
- 基于layui前后端分离的企业级微服务架构
- 兼容spring cloud netflix & spring cloud alibaba
- 优化Spring Security内部实现,实现API调用的统一出口和权限认证授权中心
- 提供完善的企业微服务流量监控,日志监控能力
- 提供完善的压力测试方案
- 提供完善的微服务部署方案
项目演示地址
http://59.110.164.254:8066/login.html 用户名/密码:admin/admin
项目监控地址
http://47.98.236.203:3000 用户名/密码:admin/1q2w3e4r
入群学习:(备注:Coder编程)
群1:483725710(满2000)
群2:897924507