diff --git a/mini-spring-cloud-examples/mini-spring-cloud-api-gateway-example/pom.xml b/mini-spring-cloud-examples/mini-spring-cloud-api-gateway-example/pom.xml new file mode 100644 index 0000000..a9e3e80 --- /dev/null +++ b/mini-spring-cloud-examples/mini-spring-cloud-api-gateway-example/pom.xml @@ -0,0 +1,43 @@ + + + + mini-spring-cloud + com.github + 1.0.0-SNAPSHOT + ../../pom.xml + + 4.0.0 + + mini-spring-cloud-api-gateway-example + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.github + mini-spring-cloud-netflix-zuul + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/mini-spring-cloud-examples/mini-spring-cloud-api-gateway-example/src/main/java/com/github/cloud/examples/ApiGatewayApplication.java b/mini-spring-cloud-examples/mini-spring-cloud-api-gateway-example/src/main/java/com/github/cloud/examples/ApiGatewayApplication.java new file mode 100644 index 0000000..793114a --- /dev/null +++ b/mini-spring-cloud-examples/mini-spring-cloud-api-gateway-example/src/main/java/com/github/cloud/examples/ApiGatewayApplication.java @@ -0,0 +1,19 @@ +package com.github.cloud.examples; + +import com.github.cloud.netflix.zuul.EnableZuulProxy; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author derek(易仁川) + * @date 2022/6/26 + */ +@EnableZuulProxy +@SpringBootApplication +public class ApiGatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(ApiGatewayApplication.class, args); + } +} diff --git a/mini-spring-cloud-examples/mini-spring-cloud-api-gateway-example/src/main/resources/application.yml b/mini-spring-cloud-examples/mini-spring-cloud-api-gateway-example/src/main/resources/application.yml new file mode 100644 index 0000000..84c6fb1 --- /dev/null +++ b/mini-spring-cloud-examples/mini-spring-cloud-api-gateway-example/src/main/resources/application.yml @@ -0,0 +1,2 @@ +server: + port: 8888 \ No newline at end of file diff --git a/mini-spring-cloud-netflix-zuul/pom.xml b/mini-spring-cloud-netflix-zuul/pom.xml index 6034937..a35a028 100644 --- a/mini-spring-cloud-netflix-zuul/pom.xml +++ b/mini-spring-cloud-netflix-zuul/pom.xml @@ -10,7 +10,6 @@ 4.0.0 mini-spring-cloud-netflix-zuul - 1.0.0-SNAPSHOT @@ -55,7 +54,6 @@ org.springframework.boot spring-boot-starter-web - test diff --git a/mini-spring-cloud-netflix-zuul/src/main/java/com/github/cloud/netflix/zuul/ZuulServerAutoConfiguration.java b/mini-spring-cloud-netflix-zuul/src/main/java/com/github/cloud/netflix/zuul/ZuulServerAutoConfiguration.java index 2df5002..4f44311 100644 --- a/mini-spring-cloud-netflix-zuul/src/main/java/com/github/cloud/netflix/zuul/ZuulServerAutoConfiguration.java +++ b/mini-spring-cloud-netflix-zuul/src/main/java/com/github/cloud/netflix/zuul/ZuulServerAutoConfiguration.java @@ -26,6 +26,6 @@ public class ZuulServerAutoConfiguration { */ @Bean public ServletRegistrationBean zuulServlet() { - return new ServletRegistrationBean<>(new ZuulServlet(), zuulProperties.getServletPattern()); + return new ServletRegistrationBean<>(new ZuulServlet(), zuulProperties.getServletPath()); } } diff --git a/mini-spring-cloud-netflix-zuul/src/main/java/com/github/cloud/netflix/zuul/filters/ZuulProperties.java b/mini-spring-cloud-netflix-zuul/src/main/java/com/github/cloud/netflix/zuul/filters/ZuulProperties.java index ccdf30c..5676571 100644 --- a/mini-spring-cloud-netflix-zuul/src/main/java/com/github/cloud/netflix/zuul/filters/ZuulProperties.java +++ b/mini-spring-cloud-netflix-zuul/src/main/java/com/github/cloud/netflix/zuul/filters/ZuulProperties.java @@ -9,25 +9,13 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties("zuul") public class ZuulProperties { - private String servletPath = "/zuul"; + 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() { + public String getServletPath() { return servletPath; } - void setServletPath(String servletPath) { + public void setServletPath(String servletPath) { this.servletPath = servletPath; } } diff --git a/pom.xml b/pom.xml index 0a22c86..e671629 100644 --- a/pom.xml +++ b/pom.xml @@ -17,13 +17,14 @@ 1.0.0-SNAPSHOT - mini-spring-cloud-examples/tutu-server mini-spring-cloud-tutu-discovery - mini-spring-cloud-examples/mini-spring-cloud-provider-example - mini-spring-cloud-examples/mini-spring-cloud-consumer-examples mini-spring-cloud-load-balancer mini-spring-cloud-openfeign mini-spring-cloud-netflix-zuul + mini-spring-cloud-examples/tutu-server + mini-spring-cloud-examples/mini-spring-cloud-provider-example + mini-spring-cloud-examples/mini-spring-cloud-consumer-examples + mini-spring-cloud-examples/mini-spring-cloud-api-gateway-example