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 serializer = jsonRedisSerializer(); - // 配置序列化 - RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig(); - RedisCacheConfiguration redisCacheConfiguration = config - .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer)) - .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(serializer)); - - RedisCacheManager cacheManager = RedisCacheManager.builder(factory) - .cacheDefaults(redisCacheConfiguration).build(); - return cacheManager; - } - - /** - * 指定的日期模式 - */ - public Jackson2JsonRedisSerializer jsonRedisSerializer() { - log.info("RedisConfiguration===>指定的日期模式"); - - ObjectMapper mapper = new ObjectMapper(); - // 设置ObjectMapper访问权限 - mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); - // 记录序列化之后的数据类型,方便反序列化 - mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL); - // 关闭默认的日期格式化方式,默认UTC日期格式 yyyy-MM-dd’T’HH:mm:ss.SSS - mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - - // LocalDatetime序列化,默认不兼容jdk8日期序列化 - JavaTimeModule timeModule = new JavaTimeModule(); - timeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); - timeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); - timeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); - timeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); - - mapper.registerModule(timeModule); - return new Jackson2JsonRedisSerializer<>(mapper, Object.class); - } -} \ No newline at end of file diff --git a/spzx-service/service-product/src/main/java/com/atguigu/product/controller/ProductController.java b/spzx-service/service-product/src/main/java/com/atguigu/product/controller/ProductController.java index 9c0c6d2..016af4a 100644 --- a/spzx-service/service-product/src/main/java/com/atguigu/product/controller/ProductController.java +++ b/spzx-service/service-product/src/main/java/com/atguigu/product/controller/ProductController.java @@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController; @Tag(name = "商品列表管理") @RestController -@RequestMapping("/api/product/") +@RequestMapping("/api/product") @Slf4j public class ProductController { @Autowired diff --git a/spzx-service/service-product/src/main/resources/logback-spring.xml b/spzx-service/service-product/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..acce308 --- /dev/null +++ b/spzx-service/service-product/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-user/Dockerfile b/spzx-service/service-user/Dockerfile new file mode 100644 index 0000000..421b7e4 --- /dev/null +++ b/spzx-service/service-user/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-user/src/main/java/com/atguigu/user/UserApplication.java b/spzx-service/service-user/src/main/java/com/atguigu/user/UserApplication.java new file mode 100644 index 0000000..b6d6037 --- /dev/null +++ b/spzx-service/service-user/src/main/java/com/atguigu/user/UserApplication.java @@ -0,0 +1,14 @@ +package com.atguigu.user; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@Slf4j +public class UserApplication { + public static void main(String[] args) { + log.info("启动===>SpringBootApplication"); + SpringApplication.run(UserApplication.class, args); + } +}