代码提交
This commit is contained in:
46
spring-cloud-demo/gateway-service/pom.xml
Normal file
46
spring-cloud-demo/gateway-service/pom.xml
Normal file
@@ -0,0 +1,46 @@
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.mangmang</groupId>
|
||||
<artifactId>spring-cloud-demo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<name>gateway-service</name>
|
||||
<artifactId>gateway-service</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.mangmang;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableEurekaClient
|
||||
public class GatewayServiceApplication {
|
||||
public static void main( String[] args ) {
|
||||
SpringApplication.run(GatewayServiceApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
# 服务器配置
|
||||
server:
|
||||
# 服务器端口号,设置为8080
|
||||
port: 8080
|
||||
|
||||
# Eureka客户端配置
|
||||
eureka:
|
||||
client:
|
||||
serviceUrl:
|
||||
# Eureka服务器的默认区域URL,指向本地8761端口的Eureka服务
|
||||
defaultZone: http://localhost:8761/eureka/
|
||||
|
||||
# Spring Cloud配置
|
||||
spring:
|
||||
cloud:
|
||||
gateway:
|
||||
discovery:
|
||||
locator:
|
||||
# 启用服务发现定位器,允许通过服务名称进行路由
|
||||
enabled: true
|
||||
routes:
|
||||
# 用户服务路由配置
|
||||
- id: user-service
|
||||
# 使用负载均衡方式指向user-service服务
|
||||
uri: lb://user-service
|
||||
predicates:
|
||||
# 匹配路径为/api/users/**的请求
|
||||
- Path=/api/users/**
|
||||
filters:
|
||||
# 去除路径中的第一个前缀
|
||||
- StripPrefix=1
|
||||
# 订单服务路由配置
|
||||
- id: order-service
|
||||
# 使用负载均衡方式指向order-service服务
|
||||
uri: lb://order-service
|
||||
predicates:
|
||||
# 匹配路径为/api/orders/**的请求
|
||||
- Path=/api/orders/**
|
||||
filters:
|
||||
# 去除路径中的第一个前缀
|
||||
- StripPrefix=1
|
||||
|
||||
# 管理端点配置
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
# 暴露所有管理端点
|
||||
include: "*"
|
||||
@@ -0,0 +1,18 @@
|
||||
# Spring 应用程序配置
|
||||
spring:
|
||||
# 应用程序相关配置
|
||||
application:
|
||||
# 应用程序名称,用于标识当前服务
|
||||
name: gateway-service
|
||||
# Spring Cloud 相关配置
|
||||
cloud:
|
||||
# 配置中心相关配置
|
||||
config:
|
||||
# 配置中心服务发现相关配置
|
||||
discovery:
|
||||
# 是否启用配置中心服务发现,true 表示启用
|
||||
enabled: true
|
||||
# 配置中心服务的服务ID,用于服务发现
|
||||
service-id: config-server
|
||||
# 是否在配置中心不可用时快速失败,true 表示快速失败
|
||||
fail-fast: true
|
||||
Reference in New Issue
Block a user