✨ 创建网关
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>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– 服务注册/发现–> -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>com.alibaba.cloud</groupId> -->
|
||||
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- 服务注册/发现-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <!– 配置中心来做配置管理–> -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>com.alibaba.cloud</groupId> -->
|
||||
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> -->
|
||||
<!-- </dependency> -->
|
||||
<!-- 配置中心来做配置管理 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
|
|
|
@ -2,8 +2,9 @@ package com.xunqi.gulimall.coupon;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
// @EnableDiscoveryClient
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class GulimallCouponApplication {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -9,10 +9,10 @@ spring:
|
|||
password: "123456"
|
||||
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
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# server-addr: localhost:8848
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.95.40:8848
|
||||
#
|
||||
# sentinel:
|
||||
# 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"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
|
@ -20,24 +20,29 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xunqi.gulimall</groupId>
|
||||
<artifactId>gulimall-common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-alibaba-sentinel-gateway -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
|
||||
<version>2.1.0.RELEASE</version>
|
||||
</dependency>
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>com.alibaba.cloud</groupId> -->
|
||||
<!-- <artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId> -->
|
||||
<!-- <version>2.1.0.RELEASE</version> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -45,10 +50,10 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.springframework.boot</groupId> -->
|
||||
<!-- <artifactId>spring-boot-starter-actuator</artifactId> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -10,13 +10,10 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|||
* (配置nacos的注册中心地址)
|
||||
* 2、编写网关配置文件
|
||||
*/
|
||||
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||
public class GulimallGatewayApplication {
|
||||
|
||||
public static void main(String[] 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>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.springframework.cloud</groupId> -->
|
||||
<!-- <artifactId>spring-cloud-starter-openfeign</artifactId> -->
|
||||
<!-- </dependency> -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -2,16 +2,17 @@ package com.xunqi.gulimall.member;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* 1、spring-session依赖
|
||||
* 2、spring-session配置
|
||||
* 3、LoginInterceptor拦截器
|
||||
*/
|
||||
|
||||
// @EnableRedisHttpSession
|
||||
// @EnableFeignClients(basePackages = "com.xunqi.gulimall.member.feign")
|
||||
// @EnableDiscoveryClient
|
||||
@EnableFeignClients(basePackages = "com.xunqi.gulimall.member.feign")
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class GulimallMemberApplication {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -2,22 +2,24 @@ server:
|
|||
port: 8000
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: gulimall-member
|
||||
datasource:
|
||||
username: root
|
||||
password: "123456"
|
||||
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
|
||||
# cloud:
|
||||
# nacos:
|
||||
# discovery:
|
||||
# server-addr: localhost:8848
|
||||
#
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.95.40:8848
|
||||
|
||||
# sentinel:
|
||||
# transport:
|
||||
# #配置sentinel dashboard地址
|
||||
# dashboard: localhost:8080
|
||||
|
||||
redis:
|
||||
# redis:
|
||||
# port: 6379
|
||||
# host: 192.168.77.130
|
||||
|
||||
|
@ -26,8 +28,7 @@ spring:
|
|||
# sentinel:
|
||||
# enabled: true
|
||||
#
|
||||
# application:
|
||||
# name: gulimall-member
|
||||
|
||||
#
|
||||
# jackson:
|
||||
# date-format: yyyy-MM-dd HH:mm:ss
|
||||
|
|
Loading…
Reference in New Issue