api-gateway-netflix-zuul
DerekYRC 2 years ago
parent 07eb8f4c15
commit 0c6fb4da0b

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>mini-spring-cloud</artifactId>
<groupId>com.github</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>mini-spring-cloud-netflix-zuul</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.netflix.zuul</groupId>
<artifactId>zuul-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
</dependencies>
</project>

@ -0,0 +1,19 @@
package com.github.cloud.netflix.zuul;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
/**
* zuul
* @author derek()
* @date 2022/6/23
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(ZuulProxyAutoConfiguration.class)
public @interface EnableZuulProxy {
}

@ -0,0 +1,11 @@
package com.github.cloud.netflix.zuul;
import org.springframework.context.annotation.Configuration;
/**
* @author derek()
* @date 2022/6/23
*/
@Configuration
public class ZuulProxyAutoConfiguration extends ZuulServerAutoConfiguration {
}

@ -0,0 +1,31 @@
package com.github.cloud.netflix.zuul;
import com.github.cloud.netflix.zuul.filters.ZuulProperties;
import com.netflix.zuul.http.ZuulServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author derek()
* @date 2022/6/23
*/
@Configuration
@EnableConfigurationProperties({ZuulProperties.class})
public class ZuulServerAutoConfiguration {
@Autowired
protected ZuulProperties zuulProperties;
/**
* ZuulServlet
* @return
*/
@Bean
public ServletRegistrationBean zuulServlet() {
return new ServletRegistrationBean<>(new ZuulServlet(), zuulProperties.getServletPattern());
}
}

@ -0,0 +1,33 @@
package com.github.cloud.netflix.zuul.filters;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author derek()
* @date 2022/6/23
*/
@ConfigurationProperties("zuul")
public class ZuulProperties {
private String servletPath = "/zuul";
public String getServletPattern() {
String path = this.servletPath;
if (!path.startsWith("/")) {
path = "/" + path;
}
if (!path.contains("*")) {
path = path.endsWith("/") ? (path + "*") : (path + "/*");
}
return path;
}
String getServletPath() {
return servletPath;
}
void setServletPath(String servletPath) {
this.servletPath = servletPath;
}
}

@ -23,6 +23,7 @@
<module>mini-spring-cloud-examples/mini-spring-cloud-consumer-examples</module> <module>mini-spring-cloud-examples/mini-spring-cloud-consumer-examples</module>
<module>mini-spring-cloud-load-balancer</module> <module>mini-spring-cloud-load-balancer</module>
<module>mini-spring-cloud-openfeign</module> <module>mini-spring-cloud-openfeign</module>
<module>mini-spring-cloud-netflix-zuul</module>
</modules> </modules>
<properties> <properties>
@ -31,6 +32,7 @@
<hutool.version>5.7.21</hutool.version> <hutool.version>5.7.21</hutool.version>
<ribbon.version>2.3.0</ribbon.version> <ribbon.version>2.3.0</ribbon.version>
<feign.version>11.8</feign.version> <feign.version>11.8</feign.version>
<zuul.version>1.3.1</zuul.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -69,6 +71,12 @@
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>com.github</groupId>
<artifactId>mini-spring-cloud-netflix-zuul</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
@ -104,6 +112,12 @@
<artifactId>feign-core</artifactId> <artifactId>feign-core</artifactId>
<version>${feign.version}</version> <version>${feign.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.netflix.zuul</groupId>
<artifactId>zuul-core</artifactId>
<version>${zuul.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

Loading…
Cancel
Save