注解优化,grpc开发

This commit is contained in:
暮光:城中城
2019-04-02 20:22:18 +08:00
parent f5e6a5998d
commit 7caebe9eaf
48 changed files with 13154 additions and 283 deletions

View File

@@ -7,7 +7,7 @@ import com.zyplayer.doc.core.json.ResponseJson;
import com.zyplayer.doc.swagger.controller.vo.LocationListVo;
import com.zyplayer.doc.swagger.controller.vo.SwaggerLocationVo;
import com.zyplayer.doc.swagger.controller.vo.SwaggerResourcesInfoVo;
import com.zyplayer.doc.swagger.framework.configuration.EnableSwaggerMgUi;
import com.zyplayer.doc.swagger.framework.configuration.EnableDocSwagger;
import com.zyplayer.doc.swagger.framework.configuration.SpringContextUtil;
import com.zyplayer.doc.swagger.framework.constant.StorageKeys;
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
@@ -83,7 +83,7 @@ public class MgDocumentController {
+ ":" + request.getServerPort() // 端口号
+ request.getContextPath();
// 是否加入自身的文档
EnableSwaggerMgUi swaggerMgUi = SpringContextUtil.getEnableSwaggerMgUi();
EnableDocSwagger swaggerMgUi = SpringContextUtil.getEnableSwaggerMgUi();
if (swaggerMgUi == null) {
resourcesSet.add(new SwaggerResourcesInfoVo(serverPath + "/swagger-resources"));
} else {
@@ -194,21 +194,21 @@ public class MgDocumentController {
// + ":" + request.getServerPort() // 端口号
// + request.getContextPath();
// // 是否加入自身的文档
// Object enableSwaggerMgUi = SpringContextUtil.getBeanWithAnnotation(EnableSwaggerMgUi.class);
// Object enableSwaggerMgUi = SpringContextUtil.getBeanWithAnnotation(EnableDocSwagger.class);
// if (enableSwaggerMgUi != null) {
// EnableSwaggerMgUi swaggerMgUi = enableSwaggerMgUi.getClass().getAnnotation(EnableSwaggerMgUi.class);
// EnableDocSwagger swaggerMgUi = enableSwaggerMgUi.getClass().getAnnotation(EnableDocSwagger.class);
// if (swaggerMgUi == null) {
// // 直接通过superclass去找
// Class<?> superclass = enableSwaggerMgUi.getClass().getSuperclass();
// if (superclass != null) {
// swaggerMgUi = superclass.getAnnotation(EnableSwaggerMgUi.class);
// swaggerMgUi = superclass.getAnnotation(EnableDocSwagger.class);
// }
// }
// if (swaggerMgUi == null) {
// // 再通过AopUtils去找
// Class<?> targetClass = AopUtils.getTargetClass(enableSwaggerMgUi);
// if (targetClass != null) {
// swaggerMgUi = targetClass.getAnnotation(EnableSwaggerMgUi.class);
// swaggerMgUi = targetClass.getAnnotation(EnableDocSwagger.class);
// }
// }
// if (swaggerMgUi == null) {

View File

@@ -1,17 +1,17 @@
package com.zyplayer.doc.swagger.framework.configuration;
import com.zyplayer.doc.swagger.framework.filter.ZyplayerProxyFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.*;
@Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
@Target(value = {java.lang.annotation.ElementType.TYPE})
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
@Import({SwaggerCommonConfiguration.class, SpringContextUtil.class, ZyplayerProxyFilter.class})
public @interface EnableSwaggerMgUi {
public @interface EnableDocSwagger {
/**
* 是否自动把自身的swagger-resources加进来

View File

@@ -16,7 +16,7 @@ import java.util.Map;
public class SpringContextUtil implements ApplicationContextAware {
public static ApplicationContext context;
private static EnableSwaggerMgUi ENABLE_SWAGGER_MG_UI;
private static EnableDocSwagger ENABLE_SWAGGER_MG_UI;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
@@ -58,25 +58,25 @@ public class SpringContextUtil implements ApplicationContextAware {
* @since 2019/1/29 12:58
* @return EnableSwaggerMgUi注解对象
**/
public static EnableSwaggerMgUi getEnableSwaggerMgUi() {
public static EnableDocSwagger getEnableSwaggerMgUi() {
if (ENABLE_SWAGGER_MG_UI != null) {
return ENABLE_SWAGGER_MG_UI;
}
Object annotation = SpringContextUtil.getBeanWithAnnotation(EnableSwaggerMgUi.class);
Object annotation = SpringContextUtil.getBeanWithAnnotation(EnableDocSwagger.class);
if (annotation != null) {
EnableSwaggerMgUi swaggerMgUi = annotation.getClass().getAnnotation(EnableSwaggerMgUi.class);
EnableDocSwagger swaggerMgUi = annotation.getClass().getAnnotation(EnableDocSwagger.class);
if (swaggerMgUi == null) {
// 直接通过superclass去找
Class<?> superclass = annotation.getClass().getSuperclass();
if (superclass != null) {
swaggerMgUi = superclass.getAnnotation(EnableSwaggerMgUi.class);
swaggerMgUi = superclass.getAnnotation(EnableDocSwagger.class);
}
}
if (swaggerMgUi == null) {
// 再通过AopUtils去找
Class<?> targetClass = AopUtils.getTargetClass(annotation);
if (targetClass != null) {
swaggerMgUi = targetClass.getAnnotation(EnableSwaggerMgUi.class);
swaggerMgUi = targetClass.getAnnotation(EnableDocSwagger.class);
}
}
if (swaggerMgUi != null) {