Skip to content

Commit

Permalink
zuul整合使用实验
Browse files Browse the repository at this point in the history
1.创建新模块`spring-cloud-zuul-10001`
  * 导入zuul依赖
  * 主程序增加注解@EnableZuulProxy @EnableEurekaClient
  * 配置application.yml,配置网关映射
  • Loading branch information
alprogor committed May 13, 2020
1 parent a0bfbb9 commit cd3e5b9
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>spring-cloud-message-service-8004</module>
<module>spring-cloud-message-service-8005</module>
<module>spring-cloud-hystrix-dashboard-9001</module>
<module>spring-cloud-zuul-10001</module>
</modules>

<!--使用dependencyManagement锁定依赖的版本 start-->
Expand Down
53 changes: 53 additions & 0 deletions spring-cloud-zuul-10001/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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>spring-cloud-demo</artifactId>
<groupId>com.progor.study</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-cloud-zuul-10001</artifactId>

<dependencies>
<!--引入公共依赖包 start-->
<dependency>
<groupId>com.progor.study</groupId>
<artifactId>spring-cloud-common-data</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--引入公共依赖包 end-->
<!--导入zuul-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<!--导入eureka-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--导入actuator-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--导入hystrix-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!--导入web相关-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

</project>
2 changes: 2 additions & 0 deletions spring-cloud-zuul-10001/spring-cloud-zuul-10001.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.progor.study;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@SpringBootApplication
@EnableZuulProxy
@EnableEurekaClient // 需要加eureka,因为他也需要拉取服务列表
public class SpringCloudZuul10001Application {

public static void main(String[] args) {
SpringApplication.run(SpringCloudZuul10001Application.class, args);
}

}
24 changes: 24 additions & 0 deletions spring-cloud-zuul-10001/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
server:
port: 10001

spring:
application:
name: spring-cloud-zuul

# 为了负载均衡之类的和拉取服务之类的,也需要配置eureka
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka
instance:
instance-id: zuul-10001.com
prefer-ip-address: true

# 配置zuul
zuul:
# prefix: /api
routes: # 配置路由
UserService:
serviceId: USERSERIVE # 服务名
path: /myuser/** # 在本地用什么来映射,比如/user/list会映射成本地的/myuser/user/list
# ignored-services: '*'

0 comments on commit cd3e5b9

Please sign in to comment.