✨ 创建网关
This commit is contained in:
parent
c09f098807
commit
f812c50f04
|
@ -0,0 +1,4 @@
|
||||||
|
# 步骤
|
||||||
|
|
||||||
|
生成:GulimallCouponApplication、GulimallMemberApplication、GulimallOrderApplication
|
||||||
|
GulimallProductApplication、GulimallWareApplication
|
|
@ -58,17 +58,17 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- <!– 服务注册/发现–> -->
|
<!-- 服务注册/发现-->
|
||||||
<!-- <dependency> -->
|
<dependency>
|
||||||
<!-- <groupId>com.alibaba.cloud</groupId> -->
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> -->
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
<!-- </dependency> -->
|
</dependency>
|
||||||
|
|
||||||
<!-- <!– 配置中心来做配置管理–> -->
|
<!-- 配置中心来做配置管理 -->
|
||||||
<!-- <dependency> -->
|
<dependency>
|
||||||
<!-- <groupId>com.alibaba.cloud</groupId> -->
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> -->
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
<!-- </dependency> -->
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.validation</groupId>
|
<groupId>javax.validation</groupId>
|
||||||
|
|
|
@ -2,8 +2,9 @@ package com.xunqi.gulimall.coupon;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
// @EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class GulimallCouponApplication {
|
public class GulimallCouponApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -9,10 +9,10 @@ spring:
|
||||||
password: "123456"
|
password: "123456"
|
||||||
url: jdbc:mysql://192.168.95.40:3306/gulimall_sms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
url: jdbc:mysql://192.168.95.40:3306/gulimall_sms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
# cloud:
|
cloud:
|
||||||
# nacos:
|
nacos:
|
||||||
# discovery:
|
discovery:
|
||||||
# server-addr: localhost:8848
|
server-addr: 192.168.95.40:8848
|
||||||
#
|
#
|
||||||
# sentinel:
|
# sentinel:
|
||||||
# transport:
|
# transport:
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: gulimall-coupon
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
config:
|
||||||
|
server-addr: 192.168.95.40:8848
|
|
@ -0,0 +1,18 @@
|
||||||
|
# 网关
|
||||||
|
|
||||||
|
## 配置路由
|
||||||
|
|
||||||
|
如果访问地址为:`http://localhost:88/?url=baidu`会跳转到百度的页面中。
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
gateway:
|
||||||
|
routes:
|
||||||
|
- id: test_route
|
||||||
|
uri: https://www.baidu.com
|
||||||
|
predicates:
|
||||||
|
- Query=url,baidu
|
||||||
|
- id: qq_route
|
||||||
|
uri: https://qq.com
|
||||||
|
predicates:
|
||||||
|
- Query=url,qq
|
||||||
|
```
|
|
@ -0,0 +1,10 @@
|
||||||
|
Dynamic Configuration Sources,没有配置动态配置源。
|
||||||
|
|
||||||
|
解决办法在`Resource`下创建文件:`config.properties`,不写东西也可。
|
||||||
|
|
||||||
|
```properties
|
||||||
|
2025-07-03 23:03:44.944 WARN 21420 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
|
||||||
|
2025-07-03 23:03:44.945 INFO 21420 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
|
||||||
|
2025-07-03 23:03:44.949 WARN 21420 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
|
||||||
|
```
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
|
@ -20,24 +20,29 @@
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.xunqi.gulimall</groupId>
|
<groupId>com.xunqi.gulimall</groupId>
|
||||||
<artifactId>gulimall-common</artifactId>
|
<artifactId>gulimall-common</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-alibaba-sentinel-gateway -->
|
<!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-alibaba-sentinel-gateway -->
|
||||||
<dependency>
|
<!-- <dependency> -->
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<!-- <groupId>com.alibaba.cloud</groupId> -->
|
||||||
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
|
<!-- <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId> -->
|
||||||
<version>2.1.0.RELEASE</version>
|
<!-- <version>2.1.0.RELEASE</version> -->
|
||||||
</dependency>
|
<!-- </dependency> -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -45,10 +50,10 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<!-- <dependency> -->
|
||||||
<groupId>org.springframework.boot</groupId>
|
<!-- <groupId>org.springframework.boot</groupId> -->
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<!-- <artifactId>spring-boot-starter-actuator</artifactId> -->
|
||||||
</dependency>
|
<!-- </dependency> -->
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,13 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1、开启服务注册发现
|
* 1、开启服务注册发现
|
||||||
* (配置nacos的注册中心地址)
|
* (配置nacos的注册中心地址)
|
||||||
* 2、编写网关配置文件
|
* 2、编写网关配置文件
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
public class GulimallGatewayApplication {
|
public class GulimallGatewayApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(GulimallGatewayApplication.class, args);
|
SpringApplication.run(GulimallGatewayApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
server:
|
||||||
|
port: 88
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: gulimall-gateway
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
server-addr: 192.168.95.40:8848
|
||||||
|
gateway:
|
||||||
|
routes:
|
||||||
|
- id: test_route
|
||||||
|
uri: https://www.baidu.com
|
||||||
|
predicates:
|
||||||
|
- Query=url,baidu
|
||||||
|
- id: qq_route
|
||||||
|
uri: https://qq.com
|
||||||
|
predicates:
|
||||||
|
- Query=url,qq
|
|
@ -0,0 +1,8 @@
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: gulimall-gateway
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
config:
|
||||||
|
server-addr: 192.168.95.40:8848
|
||||||
|
namespace: gateway
|
|
@ -50,10 +50,10 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency> -->
|
<dependency>
|
||||||
<!-- <groupId>org.springframework.cloud</groupId> -->
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<!-- <artifactId>spring-cloud-starter-openfeign</artifactId> -->
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
<!-- </dependency> -->
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
|
@ -2,16 +2,17 @@ package com.xunqi.gulimall.member;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1、spring-session依赖
|
* 1、spring-session依赖
|
||||||
* 2、spring-session配置
|
* 2、spring-session配置
|
||||||
* 3、LoginInterceptor拦截器
|
* 3、LoginInterceptor拦截器
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @EnableRedisHttpSession
|
// @EnableRedisHttpSession
|
||||||
// @EnableFeignClients(basePackages = "com.xunqi.gulimall.member.feign")
|
@EnableFeignClients(basePackages = "com.xunqi.gulimall.member.feign")
|
||||||
// @EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class GulimallMemberApplication {
|
public class GulimallMemberApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -2,22 +2,24 @@ server:
|
||||||
port: 8000
|
port: 8000
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
|
application:
|
||||||
|
name: gulimall-member
|
||||||
datasource:
|
datasource:
|
||||||
username: root
|
username: root
|
||||||
password: "123456"
|
password: "123456"
|
||||||
url: jdbc:mysql://192.168.95.40:3306/gulimall_ums?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
url: jdbc:mysql://192.168.95.40:3306/gulimall_ums?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
# cloud:
|
cloud:
|
||||||
# nacos:
|
nacos:
|
||||||
# discovery:
|
discovery:
|
||||||
# server-addr: localhost:8848
|
server-addr: 192.168.95.40:8848
|
||||||
#
|
|
||||||
# sentinel:
|
# sentinel:
|
||||||
# transport:
|
# transport:
|
||||||
# #配置sentinel dashboard地址
|
# #配置sentinel dashboard地址
|
||||||
# dashboard: localhost:8080
|
# dashboard: localhost:8080
|
||||||
|
|
||||||
redis:
|
# redis:
|
||||||
# port: 6379
|
# port: 6379
|
||||||
# host: 192.168.77.130
|
# host: 192.168.77.130
|
||||||
|
|
||||||
|
@ -26,8 +28,7 @@ spring:
|
||||||
# sentinel:
|
# sentinel:
|
||||||
# enabled: true
|
# enabled: true
|
||||||
#
|
#
|
||||||
# application:
|
|
||||||
# name: gulimall-member
|
|
||||||
#
|
#
|
||||||
# jackson:
|
# jackson:
|
||||||
# date-format: yyyy-MM-dd HH:mm:ss
|
# date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
|
Loading…
Reference in New Issue