From f812c50f045fe10128ee0f40ec75840c2135afc0 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Thu, 3 Jul 2025 23:19:39 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=88=9B=E5=BB=BA=E7=BD=91?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReadMe.md | 4 +++ gulimall-common/pom.xml | 20 +++++++------- .../coupon/GulimallCouponApplication.java | 3 ++- .../src/main/resources/application.yml | 8 +++--- .../src/main/resources/bootstrap.yml | 7 +++++ gulimall-gateway/ReadMe/1.创建测试网关.md | 18 +++++++++++++ gulimall-gateway/ReadMe/警告和错误解决.md | 10 +++++++ gulimall-gateway/pom.xml | 27 +++++++++++-------- .../gateway/GulimallGatewayApplication.java | 5 +--- .../src/main/resources/application.yml | 20 ++++++++++++++ .../src/main/resources/bootstrap.yml | 8 ++++++ .../src/main/resources/config.properties | 0 gulimall-member/pom.xml | 8 +++--- .../member/GulimallMemberApplication.java | 7 ++--- .../src/main/resources/application.yml | 17 ++++++------ 15 files changed, 117 insertions(+), 45 deletions(-) create mode 100644 ReadMe.md create mode 100644 gulimall-coupon/src/main/resources/bootstrap.yml create mode 100644 gulimall-gateway/ReadMe/1.创建测试网关.md create mode 100644 gulimall-gateway/ReadMe/警告和错误解决.md create mode 100644 gulimall-gateway/src/main/resources/application.yml create mode 100644 gulimall-gateway/src/main/resources/bootstrap.yml create mode 100644 gulimall-gateway/src/main/resources/config.properties diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..08a3073 --- /dev/null +++ b/ReadMe.md @@ -0,0 +1,4 @@ +# 步骤 + +生成:GulimallCouponApplication、GulimallMemberApplication、GulimallOrderApplication +GulimallProductApplication、GulimallWareApplication \ No newline at end of file diff --git a/gulimall-common/pom.xml b/gulimall-common/pom.xml index 69455c6..4b68805 100644 --- a/gulimall-common/pom.xml +++ b/gulimall-common/pom.xml @@ -58,17 +58,17 @@ provided - - - - - + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + - - - - - + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + javax.validation diff --git a/gulimall-coupon/src/main/java/com/xunqi/gulimall/coupon/GulimallCouponApplication.java b/gulimall-coupon/src/main/java/com/xunqi/gulimall/coupon/GulimallCouponApplication.java index 784f3cf..9bd2166 100644 --- a/gulimall-coupon/src/main/java/com/xunqi/gulimall/coupon/GulimallCouponApplication.java +++ b/gulimall-coupon/src/main/java/com/xunqi/gulimall/coupon/GulimallCouponApplication.java @@ -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) { diff --git a/gulimall-coupon/src/main/resources/application.yml b/gulimall-coupon/src/main/resources/application.yml index 420f68e..a566c46 100644 --- a/gulimall-coupon/src/main/resources/application.yml +++ b/gulimall-coupon/src/main/resources/application.yml @@ -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: diff --git a/gulimall-coupon/src/main/resources/bootstrap.yml b/gulimall-coupon/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..51ee555 --- /dev/null +++ b/gulimall-coupon/src/main/resources/bootstrap.yml @@ -0,0 +1,7 @@ +spring: + application: + name: gulimall-coupon + cloud: + nacos: + config: + server-addr: 192.168.95.40:8848 diff --git a/gulimall-gateway/ReadMe/1.创建测试网关.md b/gulimall-gateway/ReadMe/1.创建测试网关.md new file mode 100644 index 0000000..bc2289a --- /dev/null +++ b/gulimall-gateway/ReadMe/1.创建测试网关.md @@ -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 +``` \ No newline at end of file diff --git a/gulimall-gateway/ReadMe/警告和错误解决.md b/gulimall-gateway/ReadMe/警告和错误解决.md new file mode 100644 index 0000000..0d6aa53 --- /dev/null +++ b/gulimall-gateway/ReadMe/警告和错误解决.md @@ -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. +``` + diff --git a/gulimall-gateway/pom.xml b/gulimall-gateway/pom.xml index f1e2db7..e5e410a 100644 --- a/gulimall-gateway/pom.xml +++ b/gulimall-gateway/pom.xml @@ -1,5 +1,5 @@ - 4.0.0 @@ -20,24 +20,29 @@ - com.xunqi.gulimall gulimall-common 0.0.1-SNAPSHOT + + org.springframework.boot + spring-boot-devtools + runtime + + org.springframework.cloud spring-cloud-starter-gateway - - com.alibaba.cloud - spring-cloud-alibaba-sentinel-gateway - 2.1.0.RELEASE - + + + + + org.springframework.boot @@ -45,10 +50,10 @@ test - - org.springframework.boot - spring-boot-starter-actuator - + + + + diff --git a/gulimall-gateway/src/main/java/com/xunqi/gulimall/gateway/GulimallGatewayApplication.java b/gulimall-gateway/src/main/java/com/xunqi/gulimall/gateway/GulimallGatewayApplication.java index 9052f2f..5732420 100644 --- a/gulimall-gateway/src/main/java/com/xunqi/gulimall/gateway/GulimallGatewayApplication.java +++ b/gulimall-gateway/src/main/java/com/xunqi/gulimall/gateway/GulimallGatewayApplication.java @@ -7,16 +7,13 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; /** * 1、开启服务注册发现 - * (配置nacos的注册中心地址) + * (配置nacos的注册中心地址) * 2、编写网关配置文件 */ - @EnableDiscoveryClient @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) public class GulimallGatewayApplication { - public static void main(String[] args) { SpringApplication.run(GulimallGatewayApplication.class, args); } - } diff --git a/gulimall-gateway/src/main/resources/application.yml b/gulimall-gateway/src/main/resources/application.yml new file mode 100644 index 0000000..edd73a1 --- /dev/null +++ b/gulimall-gateway/src/main/resources/application.yml @@ -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 \ No newline at end of file diff --git a/gulimall-gateway/src/main/resources/bootstrap.yml b/gulimall-gateway/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..0f3dd6d --- /dev/null +++ b/gulimall-gateway/src/main/resources/bootstrap.yml @@ -0,0 +1,8 @@ +spring: + application: + name: gulimall-gateway + cloud: + nacos: + config: + server-addr: 192.168.95.40:8848 + namespace: gateway \ No newline at end of file diff --git a/gulimall-gateway/src/main/resources/config.properties b/gulimall-gateway/src/main/resources/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/gulimall-member/pom.xml b/gulimall-member/pom.xml index a243826..3637f52 100644 --- a/gulimall-member/pom.xml +++ b/gulimall-member/pom.xml @@ -50,10 +50,10 @@ org.springframework.boot spring-boot-starter-web - - - - + + org.springframework.cloud + spring-cloud-starter-openfeign + org.springframework.boot diff --git a/gulimall-member/src/main/java/com/xunqi/gulimall/member/GulimallMemberApplication.java b/gulimall-member/src/main/java/com/xunqi/gulimall/member/GulimallMemberApplication.java index 0031f0e..b6c0523 100644 --- a/gulimall-member/src/main/java/com/xunqi/gulimall/member/GulimallMemberApplication.java +++ b/gulimall-member/src/main/java/com/xunqi/gulimall/member/GulimallMemberApplication.java @@ -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) { diff --git a/gulimall-member/src/main/resources/application.yml b/gulimall-member/src/main/resources/application.yml index 9e0c134..f2e0d56 100644 --- a/gulimall-member/src/main/resources/application.yml +++ b/gulimall-member/src/main/resources/application.yml @@ -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