Commit ad20175c authored by 李成龙's avatar 李成龙

优化swagger

parent 15461b6e
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
......
...@@ -30,29 +30,30 @@ import springfox.documentation.service.SecurityScheme; ...@@ -30,29 +30,30 @@ import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
/** /**
* @Author lichenglong * @Author lichenglong
*/ */
//@Configuration
//@EnableSwagger2
//@EnableKnife4j
//@Import(BeanValidatorPluginsConfiguration.class)
@Configuration @Configuration
@EnableSwagger2 @EnableSwagger2WebMvc
@EnableKnife4j public class Swagger2Config {
@Import(BeanValidatorPluginsConfiguration.class)
public class Swagger2Config implements WebMvcConfigurer {
/** /**
* *
* 显示swagger-ui.html文档展示页,还必须注入swagger资源: * 显示swagger-ui.html文档展示页,还必须注入swagger资源:
* // *
* @param registry * @param registry
*/ */
@Override // @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { // public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); // registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); // registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); // registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
} // }
/** /**
* swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等 * swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
...@@ -71,9 +72,9 @@ public class Swagger2Config implements WebMvcConfigurer { ...@@ -71,9 +72,9 @@ public class Swagger2Config implements WebMvcConfigurer {
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any()) .paths(PathSelectors.any())
.build() .build();
.securitySchemes(Collections.singletonList(securityScheme())) // .securitySchemes(Collections.singletonList(securityScheme()))
.securityContexts(securityContexts()); // .securityContexts(securityContexts());
//.globalOperationParameters(setHeaderToken()); //.globalOperationParameters(setHeaderToken());
} }
...@@ -83,21 +84,21 @@ public class Swagger2Config implements WebMvcConfigurer { ...@@ -83,21 +84,21 @@ public class Swagger2Config implements WebMvcConfigurer {
* http://localhost:8888/webjars/springfox-swagger-ui/o2c.html * http://localhost:8888/webjars/springfox-swagger-ui/o2c.html
* @return * @return
*/ */
@Bean // @Bean
SecurityScheme securityScheme() { // SecurityScheme securityScheme() {
return new ApiKey(CommonConstant.X_ACCESS_TOKEN, CommonConstant.X_ACCESS_TOKEN, "header"); // return new ApiKey(CommonConstant.X_ACCESS_TOKEN, CommonConstant.X_ACCESS_TOKEN, "header");
} // }
/** /**
* JWT token * JWT token
* @return * @return
*/ */
private List<Parameter> setHeaderToken() { // private List<Parameter> setHeaderToken() {
ParameterBuilder tokenPar = new ParameterBuilder(); // ParameterBuilder tokenPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<>(); // List<Parameter> pars = new ArrayList<>();
tokenPar.name(CommonConstant.X_ACCESS_TOKEN).description("token").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); // tokenPar.name(CommonConstant.X_ACCESS_TOKEN).description("token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
pars.add(tokenPar.build()); // pars.add(tokenPar.build());
return pars; // return pars;
} // }
/** /**
* api文档的详细信息函数,注意这里的注解引用的是哪个 * api文档的详细信息函数,注意这里的注解引用的是哪个
...@@ -123,22 +124,22 @@ public class Swagger2Config implements WebMvcConfigurer { ...@@ -123,22 +124,22 @@ public class Swagger2Config implements WebMvcConfigurer {
/** /**
* 新增 securityContexts 保持登录状态 * 新增 securityContexts 保持登录状态
*/ */
private List<SecurityContext> securityContexts() { // private List<SecurityContext> securityContexts() {
return new ArrayList( // return new ArrayList(
Collections.singleton(SecurityContext.builder() // Collections.singleton(SecurityContext.builder()
.securityReferences(defaultAuth()) // .securityReferences(defaultAuth())
.forPaths(PathSelectors.regex("^(?!auth).*$")) // .forPaths(PathSelectors.regex("^(?!auth).*$"))
.build()) // .build())
); // );
} // }
//
private List<SecurityReference> defaultAuth() { // private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); // AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; // AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope; // authorizationScopes[0] = authorizationScope;
return new ArrayList( // return new ArrayList(
Collections.singleton(new SecurityReference(CommonConstant.X_ACCESS_TOKEN, authorizationScopes))); // Collections.singleton(new SecurityReference(CommonConstant.X_ACCESS_TOKEN, authorizationScopes)));
} // }
} }
package org.typroject.tyboot.core.restful.doc;
/**
* 此类是为了覆盖原有类,为空,不用写具体实现
* @author lichenglong
*
*/
public class Swagger2 {
}
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
......
package com.yeejoin.amos; package com.yeejoin.amos;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -15,7 +18,8 @@ import org.springframework.context.annotation.ComponentScan; ...@@ -15,7 +18,8 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import com.yeejoin.amos.boot.biz.common.utils.oConvertUtils;
/** /**
* <pre> * <pre>
...@@ -26,7 +30,6 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -26,7 +30,6 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement @EnableTransactionManagement
@EnableConfigurationProperties @EnableConfigurationProperties
@EnableSwagger2
@ServletComponentScan @ServletComponentScan
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients @EnableFeignClients
...@@ -42,17 +45,17 @@ public class AmosJcsApplication ...@@ -42,17 +45,17 @@ public class AmosJcsApplication
{ {
private static final Logger logger = LoggerFactory.getLogger(AmosJcsApplication.class); private static final Logger logger = LoggerFactory.getLogger(AmosJcsApplication.class);
public static void main( String[] args ) public static void main( String[] args ) throws UnknownHostException
{ {
ConfigurableApplicationContext context = SpringApplication.run(AmosJcsApplication.class, args); ConfigurableApplicationContext context = SpringApplication.run(AmosJcsApplication.class, args);
Environment environment = context.getEnvironment(); Environment env = context.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = oConvertUtils.getString(env.getProperty("server.servlet.context-path"));
logger.info("The requested service of " + environment.getProperty("spring.application.name") logger.info("\n----------------------------------------------------------\n\t" +
+ " has already been started in " "Application Jeecg-Boot is running! Access URLs:\n\t" +
+ environment.getProperty("spring.profiles.active") + "" "Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
+ " environment,and service's url is 'http://localhost:" "----------------------------------------------------------");
+ environment.getProperty("server.port")
+ environment.getProperty("server.servlet.context-path") + "/swagger-ui.html'");
} }
} }
spring.application.name=AIRPORT spring.application.name=AIRPORT
server.servlet.context-path=/airPort
server.port=11000 server.port=11000
spring.profiles.active=dev spring.profiles.active=dev
#swagger开启
#swagger.enable=true
# 是否停用Knife4j文档
knife4j.production=false
knife4j.basic.enable=false
#knife4j.basic.username=jeecg
#knife4j.basic.password=jeecg1314
\ No newline at end of file
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
......
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
......
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
......
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
......
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
......
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
......
...@@ -16,7 +16,6 @@ import org.springframework.context.annotation.ComponentScan; ...@@ -16,7 +16,6 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/** /**
* <pre> * <pre>
...@@ -28,7 +27,6 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -28,7 +27,6 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement @EnableTransactionManagement
@EnableConfigurationProperties @EnableConfigurationProperties
@EnableSwagger2
@ServletComponentScan @ServletComponentScan
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients @EnableFeignClients
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment