From 7f08af15b36a7dd3682f5b60672e96c6f2ea7975 Mon Sep 17 00:00:00 2001
From: bunny <1319900154@qq.com>
Date: Wed, 27 Mar 2024 18:58:42 +0800
Subject: [PATCH] =?UTF-8?q?feat(=E4=BF=AE=E5=A4=8D):=20=E5=85=B1=E7=94=A8?=
=?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=B7=A8=E5=9F=9F=EF=BC=8C=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?docker=E6=96=87=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: bunny <1319900154@qq.com>
---
.../spzx/manger/MangerApplication.java | 1 +
.../src/main/resources/logback-spring.xml | 57 +++++++++++
spzx-server-gateway/Dockerfile | 20 ++++
spzx-server-gateway/pom.xml | 7 +-
.../atguigu/gateway/GatewayApplication.java | 3 +
.../src/main/resources/application.yml | 20 ++--
.../src/main/resources/logback-spring.xml | 57 +++++++++++
spzx-service/service-order/Dockerfile | 20 ++++
.../com/atguigu/order/OrderApplication.java | 14 +++
spzx-service/service-product/Dockerfile | 20 ++++
.../atguigu/product/ProductApplication.java | 3 +
.../product/config/RedisConfiguration.java | 99 -------------------
.../product/controller/ProductController.java | 2 +-
.../src/main/resources/logback-spring.xml | 57 +++++++++++
spzx-service/service-user/Dockerfile | 20 ++++
.../com/atguigu/user/UserApplication.java | 14 +++
16 files changed, 300 insertions(+), 114 deletions(-)
create mode 100644 spzx-manager/src/main/resources/logback-spring.xml
create mode 100644 spzx-server-gateway/Dockerfile
create mode 100644 spzx-server-gateway/src/main/resources/logback-spring.xml
create mode 100644 spzx-service/service-order/Dockerfile
create mode 100644 spzx-service/service-order/src/main/java/com/atguigu/order/OrderApplication.java
create mode 100644 spzx-service/service-product/Dockerfile
delete mode 100644 spzx-service/service-product/src/main/java/com/atguigu/product/config/RedisConfiguration.java
create mode 100644 spzx-service/service-product/src/main/resources/logback-spring.xml
create mode 100644 spzx-service/service-user/Dockerfile
create mode 100644 spzx-service/service-user/src/main/java/com/atguigu/user/UserApplication.java
diff --git a/spzx-manager/src/main/java/com/atguigu/spzx/manger/MangerApplication.java b/spzx-manager/src/main/java/com/atguigu/spzx/manger/MangerApplication.java
index 6995570..4d0d57f 100644
--- a/spzx-manager/src/main/java/com/atguigu/spzx/manger/MangerApplication.java
+++ b/spzx-manager/src/main/java/com/atguigu/spzx/manger/MangerApplication.java
@@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@Slf4j
public class MangerApplication {
public static void main(String[] args) {
+ log.info("启动===>MangerApplication");
SpringApplication.run(MangerApplication.class, args);
}
}
diff --git a/spzx-manager/src/main/resources/logback-spring.xml b/spzx-manager/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..acce308
--- /dev/null
+++ b/spzx-manager/src/main/resources/logback-spring.xml
@@ -0,0 +1,57 @@
+
+
+
+ logback
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ INFO
+
+
+ ${CONSOLE_LOG_PATTERN}
+ ${ENCODING}
+
+
+
+
+
+ ${log.path}//log.log
+ true
+
+ %date{yyyy-MM-dd HH:mm:ss} %msg%n
+ ${ENCODING}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spzx-server-gateway/Dockerfile b/spzx-server-gateway/Dockerfile
new file mode 100644
index 0000000..421b7e4
--- /dev/null
+++ b/spzx-server-gateway/Dockerfile
@@ -0,0 +1,20 @@
+FROM openjdk:18
+
+#系统编码
+ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
+
+# 设置时区,构建镜像时执行的命令
+RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
+RUN echo "Asia/Shanghai" > /etc/timezone
+
+# 设定工作目录
+WORKDIR /home/bunny
+
+# 复制jar包
+COPY target/sky-server-1.0-SNAPSHOT.jar /home/bunny/app.jar
+
+#启动容器时的进程
+ENTRYPOINT ["java","-jar","/home/bunny/app.jar"]
+
+#暴露 8080 端口
+EXPOSE 8080
\ No newline at end of file
diff --git a/spzx-server-gateway/pom.xml b/spzx-server-gateway/pom.xml
index 30adc19..1e454c5 100644
--- a/spzx-server-gateway/pom.xml
+++ b/spzx-server-gateway/pom.xml
@@ -18,12 +18,11 @@
+
- com.atguigu
- common-util
- 1.0-SNAPSHOT
+ org.projectlombok
+ lombok
-
org.springframework.cloud
diff --git a/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java b/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java
index f999f80..2625f39 100644
--- a/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java
+++ b/spzx-server-gateway/src/main/java/com/atguigu/gateway/GatewayApplication.java
@@ -1,11 +1,14 @@
package com.atguigu.gateway;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
+@Slf4j
public class GatewayApplication {
public static void main(String[] args) {
+ log.info("启动===>SpringBootApplication");
SpringApplication.run(GatewayApplication.class, args);
}
}
\ No newline at end of file
diff --git a/spzx-server-gateway/src/main/resources/application.yml b/spzx-server-gateway/src/main/resources/application.yml
index e36cd0a..352c3b7 100644
--- a/spzx-server-gateway/src/main/resources/application.yml
+++ b/spzx-server-gateway/src/main/resources/application.yml
@@ -17,16 +17,16 @@ spring:
locator:
enabled: true
# 解决跨域
- globalcors:
- cors-configurations:
- '[/**]':
- allowedOriginPatterns: "*"
- # 允许请求中携带的头信息
- allowedHeaders: "*"
- # 运行跨域的请求方式
- allowedMethods: "*"
- # 跨域检测的有效期,单位s
- maxAge: 36000
+ # globalcors:
+ # cors-configurations:
+ # '[/**]':
+ # allowedOriginPatterns: "*"
+ # # 允许请求中携带的头信息
+ # allowedHeaders: "*"
+ # # 运行跨域的请求方式
+ # allowedMethods: "*"
+ # # 跨域检测的有效期,单位s
+ # maxAge: 36000
# 路由
routes:
- id: service-product
diff --git a/spzx-server-gateway/src/main/resources/logback-spring.xml b/spzx-server-gateway/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..acce308
--- /dev/null
+++ b/spzx-server-gateway/src/main/resources/logback-spring.xml
@@ -0,0 +1,57 @@
+
+
+
+ logback
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ INFO
+
+
+ ${CONSOLE_LOG_PATTERN}
+ ${ENCODING}
+
+
+
+
+
+ ${log.path}//log.log
+ true
+
+ %date{yyyy-MM-dd HH:mm:ss} %msg%n
+ ${ENCODING}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spzx-service/service-order/Dockerfile b/spzx-service/service-order/Dockerfile
new file mode 100644
index 0000000..421b7e4
--- /dev/null
+++ b/spzx-service/service-order/Dockerfile
@@ -0,0 +1,20 @@
+FROM openjdk:18
+
+#系统编码
+ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
+
+# 设置时区,构建镜像时执行的命令
+RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
+RUN echo "Asia/Shanghai" > /etc/timezone
+
+# 设定工作目录
+WORKDIR /home/bunny
+
+# 复制jar包
+COPY target/sky-server-1.0-SNAPSHOT.jar /home/bunny/app.jar
+
+#启动容器时的进程
+ENTRYPOINT ["java","-jar","/home/bunny/app.jar"]
+
+#暴露 8080 端口
+EXPOSE 8080
\ No newline at end of file
diff --git a/spzx-service/service-order/src/main/java/com/atguigu/order/OrderApplication.java b/spzx-service/service-order/src/main/java/com/atguigu/order/OrderApplication.java
new file mode 100644
index 0000000..8af9e3a
--- /dev/null
+++ b/spzx-service/service-order/src/main/java/com/atguigu/order/OrderApplication.java
@@ -0,0 +1,14 @@
+package com.atguigu.order;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@Slf4j
+public class OrderApplication {
+ public static void main(String[] args) {
+ log.info("启动===>OrderApplication");
+ SpringApplication.run(OrderApplication.class, args);
+ }
+}
diff --git a/spzx-service/service-product/Dockerfile b/spzx-service/service-product/Dockerfile
new file mode 100644
index 0000000..421b7e4
--- /dev/null
+++ b/spzx-service/service-product/Dockerfile
@@ -0,0 +1,20 @@
+FROM openjdk:18
+
+#系统编码
+ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
+
+# 设置时区,构建镜像时执行的命令
+RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
+RUN echo "Asia/Shanghai" > /etc/timezone
+
+# 设定工作目录
+WORKDIR /home/bunny
+
+# 复制jar包
+COPY target/sky-server-1.0-SNAPSHOT.jar /home/bunny/app.jar
+
+#启动容器时的进程
+ENTRYPOINT ["java","-jar","/home/bunny/app.jar"]
+
+#暴露 8080 端口
+EXPOSE 8080
\ No newline at end of file
diff --git a/spzx-service/service-product/src/main/java/com/atguigu/product/ProductApplication.java b/spzx-service/service-product/src/main/java/com/atguigu/product/ProductApplication.java
index 32e40d4..ddbfb01 100644
--- a/spzx-service/service-product/src/main/java/com/atguigu/product/ProductApplication.java
+++ b/spzx-service/service-product/src/main/java/com/atguigu/product/ProductApplication.java
@@ -5,13 +5,16 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@EnableCaching// 开启缓存注解
@MapperScan("com.atguigu.product.mapper")
+@ComponentScan("com.atguigu")
@Slf4j
public class ProductApplication {
public static void main(String[] args) {
+ log.info("启动===>ProductApplication");
SpringApplication.run(ProductApplication.class, args);
}
}
\ No newline at end of file
diff --git a/spzx-service/service-product/src/main/java/com/atguigu/product/config/RedisConfiguration.java b/spzx-service/service-product/src/main/java/com/atguigu/product/config/RedisConfiguration.java
deleted file mode 100644
index 7850f3b..0000000
--- a/spzx-service/service-product/src/main/java/com/atguigu/product/config/RedisConfiguration.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package com.atguigu.product.config;
-
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.fasterxml.jackson.annotation.PropertyAccessor;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
-import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
-import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
-import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
-import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
-import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.cache.CacheManager;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.cache.RedisCacheConfiguration;
-import org.springframework.data.redis.cache.RedisCacheManager;
-import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
-import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
-import org.springframework.data.redis.serializer.RedisSerializationContext;
-import org.springframework.data.redis.serializer.StringRedisSerializer;
-
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-
-@Configuration
-@Slf4j
-public class RedisConfiguration {
- /**
- * 使用StringRedisSerializer序列化为字符串
- */
- @Bean
- public RedisTemplate redisTemplate(LettuceConnectionFactory connectionFactory) {
- log.info("RedisConfiguration===>使用StringRedisSerializer序列化为字符串");
-
- RedisTemplate redisTemplate = new RedisTemplate<>();
- redisTemplate.setConnectionFactory(connectionFactory);
- // 设置key序列化为string
- redisTemplate.setKeySerializer(new StringRedisSerializer());
- // 设置value序列化为JSON,使用GenericJackson2JsonRedisSerializer替换默认序列化
- redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
- redisTemplate.setHashKeySerializer(new StringRedisSerializer());
- redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
-
- return redisTemplate;
- }
-
- /**
- * 解决cache(@Cacheable)把数据缓存到redis中的value是乱码问题
- */
- @Bean
- @SuppressWarnings("all")
- public CacheManager cacheManager(RedisConnectionFactory factory) {
- log.info("RedisConfiguration===>解决cache(@Cacheable)把数据缓存到redis中的value是乱码问题");
-
- StringRedisSerializer redisSerializer = new StringRedisSerializer();
- // json序列化
- Jackson2JsonRedisSerializer