-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.创建新模块`spring-cloud-zuul-10001` * 导入zuul依赖 * 主程序增加注解@EnableZuulProxy @EnableEurekaClient * 配置application.yml,配置网关映射
- Loading branch information
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" /> |
17 changes: 17 additions & 0 deletions
17
spring-cloud-zuul-10001/src/main/java/com/progor/study/SpringCloudZuul10001Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
spring-cloud-zuul-10001/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '*' |