♻️ 重构代码。 动态路由部分抽取成公用组件

This commit is contained in:
冷冷 committed 2018-11-05 20:59:42 +08:00
1 parent d7b4cbfa60
commit e64d260712
12 files changed
+135 -9

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~
~ Copyright (c) 2018-2025, lengleng All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
~ modification, are permitted provided that the following conditions are met:
~
~ Redistributions of source code must retain the above copyright notice,
~ this list of conditions and the following disclaimer.
~ Redistributions in binary form must reproduce the above copyright
~ notice, this list of conditions and the following disclaimer in the
~ documentation and/or other materials provided with the distribution.
~ Neither the name of the pig4cloud.com developer nor the names of its
~ contributors may be used to endorse or promote products derived from
~ this software without specific prior written permission.
~ Author: lengleng (wangiegie@gmail.com)
~
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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.pig4cloud</groupId>
<artifactId>pigx-common</artifactId>
<version>${pigx.version}</version>
</parent>
<artifactId>pigx-common-gateway</artifactId>
<packaging>jar</packaging>
<description>pigx gateway</description>
<dependencies>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-core</artifactId>
<version>${pigx.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gateway-core</artifactId>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.gateway.annotation;
import com.pig4cloud.pigx.common.gateway.configuration.DynamicRouteAutoConfiguration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
/**
* @author lengleng
* @date 2018/11/5
* <p>
* 开启pigx 动态路由
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import(DynamicRouteAutoConfiguration.class)
public @interface EnablePigxDynamicRoute {
}
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.common.gateway.configuration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
* @author lengleng
* @date 2018/11/5
* <p>
* 动态路由配置类
*/
@Configuration
@ComponentScan("com.pig4cloud.pigx.common.gateway.support")
public class DynamicRouteAutoConfiguration {
}
@@ -15,7 +15,7 @@
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.gateway.support;
package com.pig4cloud.pigx.common.gateway.support;
import cn.hutool.json.JSONObject;
import com.pig4cloud.pigx.common.core.util.R;
@@ -15,12 +15,12 @@
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.gateway.support;
package com.pig4cloud.pigx.common.gateway.support;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.gateway.support.vo.RouteDefinitionVo;
import com.pig4cloud.pigx.common.gateway.vo.RouteDefinitionVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
import org.springframework.cloud.gateway.filter.FilterDefinition;
@@ -15,7 +15,7 @@
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.gateway.support;
package com.pig4cloud.pigx.common.gateway.support;
import org.springframework.context.ApplicationEvent;
@@ -15,10 +15,10 @@
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.gateway.support;
package com.pig4cloud.pigx.common.gateway.support;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.gateway.support.vo.RouteDefinitionVo;
import com.pig4cloud.pigx.common.gateway.vo.RouteDefinitionVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
@@ -15,10 +15,10 @@
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.gateway.support;
package com.pig4cloud.pigx.common.gateway.support;
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
import com.pig4cloud.pigx.gateway.support.vo.RouteDefinitionVo;
import com.pig4cloud.pigx.common.gateway.vo.RouteDefinitionVo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
@@ -15,7 +15,8 @@
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.gateway.support.vo;
package com.pig4cloud.pigx.common.gateway.vo
;
import org.springframework.cloud.gateway.route.RouteDefinition;
+1
View File
@@ -36,6 +36,7 @@
<module>pigx-common-cache</module>
<module>pigx-common-core</module>
<module>pigx-common-job</module>
<module>pigx-common-gateway</module>
<module>pigx-common-log</module>
<module>pigx-common-security</module>
<module>pigx-common-swagger</module>
+6
View File
@@ -42,6 +42,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
<!--动态路由组件-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-gateway</artifactId>
<version>${pigx.version}</version>
</dependency>
<!--配置中心客户端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
@@ -20,6 +20,7 @@
package com.pig4cloud.pigx.gateway;
import com.pig4cloud.pigx.common.gateway.annotation.EnablePigxDynamicRoute;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
@@ -28,6 +29,7 @@ import org.springframework.cloud.client.SpringCloudApplication;
* @date 2018年06月21日
* 网关应用
*/
@EnablePigxDynamicRoute
@SpringCloudApplication
public class PigxGatewayApplication {