From 62c127525e4ac1ed57601ff0464f0bc52f56773d Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Tue, 8 Nov 2022 22:13:12 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=907.3.2=E3=80=91=E3=80=90customer?= =?UTF-8?q?=E3=80=91=E6=9B=B4=E6=96=B0=E7=BC=93=E5=AD=98=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=A3=85=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customer-spring-boot-starter/pom.xml | 9 ++- ... GunsCustomerMemoryAutoConfiguration.java} | 6 +- .../GunsCustomerRedisAutoConfiguration.java | 59 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 3 +- 4 files changed, 72 insertions(+), 5 deletions(-) rename kernel-s-customer/customer-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/customer/starter/{GunsCustomerAutoConfiguration.java => GunsCustomerMemoryAutoConfiguration.java} (93%) create mode 100644 kernel-s-customer/customer-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/customer/starter/GunsCustomerRedisAutoConfiguration.java diff --git a/kernel-s-customer/customer-spring-boot-starter/pom.xml b/kernel-s-customer/customer-spring-boot-starter/pom.xml index 7569825bf..3b93e9e01 100644 --- a/kernel-s-customer/customer-spring-boot-starter/pom.xml +++ b/kernel-s-customer/customer-spring-boot-starter/pom.xml @@ -24,11 +24,18 @@ ${roses.version} - + cn.stylefeng.roses cache-sdk-memory ${roses.version} + true + + + cn.stylefeng.roses + cache-sdk-redis + ${roses.version} + true diff --git a/kernel-s-customer/customer-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/customer/starter/GunsCustomerAutoConfiguration.java b/kernel-s-customer/customer-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/customer/starter/GunsCustomerMemoryAutoConfiguration.java similarity index 93% rename from kernel-s-customer/customer-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/customer/starter/GunsCustomerAutoConfiguration.java rename to kernel-s-customer/customer-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/customer/starter/GunsCustomerMemoryAutoConfiguration.java index 69da9f1ba..1502ea2f7 100644 --- a/kernel-s-customer/customer-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/customer/starter/GunsCustomerAutoConfiguration.java +++ b/kernel-s-customer/customer-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/customer/starter/GunsCustomerMemoryAutoConfiguration.java @@ -30,7 +30,7 @@ import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi; import cn.stylefeng.roses.kernel.customer.api.expander.CustomerConfigExpander; import cn.stylefeng.roses.kernel.customer.api.pojo.CustomerInfo; import cn.stylefeng.roses.kernel.customer.modular.cache.CustomerMemoryCache; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -41,7 +41,8 @@ import org.springframework.context.annotation.Configuration; * @date 2021/6/7 11:32 */ @Configuration -public class GunsCustomerAutoConfiguration { +@ConditionalOnMissingClass("org.springframework.data.redis.connection.RedisConnectionFactory") +public class GunsCustomerMemoryAutoConfiguration { /** * C端用户的缓存 @@ -50,7 +51,6 @@ public class GunsCustomerAutoConfiguration { * @date 2021/6/8 22:41 */ @Bean - @ConditionalOnMissingBean(name = "customerInfoCacheOperatorApi") public CacheOperatorApi customerInfoCacheOperatorApi() { TimedCache customerInfoTimedCache = CacheUtil.newTimedCache(CustomerConfigExpander.getCustomerCacheExpiredSeconds() * 1000); return new CustomerMemoryCache(customerInfoTimedCache); diff --git a/kernel-s-customer/customer-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/customer/starter/GunsCustomerRedisAutoConfiguration.java b/kernel-s-customer/customer-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/customer/starter/GunsCustomerRedisAutoConfiguration.java new file mode 100644 index 000000000..29311103a --- /dev/null +++ b/kernel-s-customer/customer-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/customer/starter/GunsCustomerRedisAutoConfiguration.java @@ -0,0 +1,59 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.customer.starter; + +import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi; +import cn.stylefeng.roses.kernel.cache.redis.util.CreateRedisTemplateUtil; +import cn.stylefeng.roses.kernel.customer.api.pojo.CustomerInfo; +import cn.stylefeng.roses.kernel.customer.modular.cache.CustomerRedisCache; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; + +/** + * C端自动装配,Redis缓存 + * + * @author fengshuonan + * @date 2021/6/7 11:32 + */ +@Configuration +@ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory") +public class GunsCustomerRedisAutoConfiguration { + + /** + * C端用户缓存,Redis缓存 + * + * @author fengshuonan + * @date 2022/11/8 22:11 + */ + @Bean + public CacheOperatorApi customerInfoCacheOperatorApi(RedisConnectionFactory redisConnectionFactory) { + RedisTemplate redisTemplate = CreateRedisTemplateUtil.createObject(redisConnectionFactory); + return new CustomerRedisCache(redisTemplate); + } + +} diff --git a/kernel-s-customer/customer-spring-boot-starter/src/main/resources/META-INF/spring.factories b/kernel-s-customer/customer-spring-boot-starter/src/main/resources/META-INF/spring.factories index de1289629..a83ad3690 100644 --- a/kernel-s-customer/customer-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/kernel-s-customer/customer-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,2 +1,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - cn.stylefeng.roses.kernel.customer.starter.GunsCustomerAutoConfiguration \ No newline at end of file + cn.stylefeng.roses.kernel.customer.starter.GunsCustomerMemoryAutoConfiguration,\ + cn.stylefeng.roses.kernel.customer.starter.GunsCustomerRedisAutoConfiguration \ No newline at end of file