当前位置: 首页 > wzjs >正文

卷帘门怎么做网站家装公司加盟

卷帘门怎么做网站,家装公司加盟,小程序开发平台好牌子推荐,华为云建网站1.单机版配置 我们先看默认SpringBoot中引入Redis时一般的流程. 在Spring Boot应用启动时,RedisAutoConfiguration类会在Spring容器初始化过程中被自动注入。具体过程如下: 启动应用:当应用程序启动时,Spring Boot会扫描类路径中的所有依赖,并通过反射加载带有@Configur…

1.单机版配置

我们先看默认SpringBoot中引入Redis时一般的流程.

在Spring Boot应用启动时,RedisAutoConfiguration类会在Spring容器初始化过程中被自动注入。具体过程如下:

  1. 启动应用:当应用程序启动时,Spring Boot会扫描类路径中的所有依赖,并通过反射加载带有@Configuration等注解的类。
  2. 处理自动配置@EnableAutoConfiguration注解是核心,它会让Spring Boot根据项目中存在的依赖和配置,推断出需要的自动配置类。Spring Boot会读取META-INF/spring.factories文件,该文件定义了多个自动装配依赖的配置类,其中就包括RedisAutoConfiguration
  3. 条件判断与加载RedisAutoConfiguration类上通常会有条件注解,如@ConditionalOnClass,该注解会判断当前配置类对应的类(如Redis客户端相关类)是否在项目中存在。如果存在,就会创建并加载RedisAutoConfiguration这个配置类。
  4. 创建相关Bean:加载完成后,RedisAutoConfiguration会根据环境配置创建相应的Bean,如RedisConnectionFactoryRedisTemplate等,并将这些Bean注入到Spring容器中。

2.集群版自定义配置

现在我们要使用集群版了,那肯定就得重新定制一些配置,用来满足我们的需求。

2.1 resources\META-INFO中的spring.factories中增加我们需要自定义的类,我们增加如下三个类来满足我们的需求。
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.common.redis.configure.RedisConfig,\com.common.redis.configure.ClusterRedisConfig,\com.common.redis.service.RedisService

这三个类中, RedisConfig适配单机版的redis, ClusterRedisConfig适配集群版的redis,RedisService封装了RedisTemplate作为服务类可以引入到我们项目中直接使用. 其中单机版和集群版配置可以通过配置文件灵活配置.

2.2 ClusterRedisConfig类,用来设置集群配置。
/*** 集群版 Redis缓存配置类,如需启用请在配置文件中新增:spring.redis.model=cluster*/
@Configuration
@ConditionalOnClass({JedisCluster.class})
@AutoConfigureBefore(RedisAutoConfiguration.class)
@ConditionalOnProperty(prefix = "spring.redis", name = "model", havingValue = "cluster")
public class ClusterRedisConfig {@Autowiredprivate RedisProperties redisProperties;@Beanpublic RedisClusterConfiguration redisClusterConfiguration() {RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(redisProperties.getCluster().getNodes());redisClusterConfiguration.setPassword(redisProperties.getPassword());return redisClusterConfiguration;}@Beanpublic RedisConnectionFactory redisConnectionFactory(RedisClusterConfiguration redisClusterConfiguration) {ClusterTopologyRefreshOptions clusterTopologyRefreshOptions = ClusterTopologyRefreshOptions.builder().enablePeriodicRefresh().enableAllAdaptiveRefreshTriggers().refreshPeriod(Duration.ofSeconds(5)).build();ClusterClientOptions clusterClientOptions = ClusterClientOptions.builder().topologyRefreshOptions(clusterTopologyRefreshOptions).build();LettuceClientConfiguration lettuceClientConfiguration = LettuceClientConfiguration.builder().readFrom(ReadFrom.REPLICA_PREFERRED).clientOptions(clusterClientOptions).build();return new LettuceConnectionFactory(redisClusterConfiguration, lettuceClientConfiguration);}/*** 设置数据存入redis 的序列化方式* </br>redisTemplate序列化默认使用的jdkSerializeable,存储二进制字节码,导致key会出现乱码,所以自定义* 序列化类** @paramredisConnectionFactory*/@Beanpublic RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) throws UnknownHostException {RedisTemplate<String, Object> template = new RedisTemplate<>();template.setConnectionFactory(redisConnectionFactory);FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);ObjectMapper mapper = new ObjectMapper();mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);serializer.setObjectMapper(mapper);// 使用StringRedisSerializer来序列化和反序列化redis的key值template.setKeySerializer(new StringRedisSerializer());template.setValueSerializer(serializer);// Hash的key也采用StringRedisSerializer的序列化方式template.setHashKeySerializer(new StringRedisSerializer());template.setHashValueSerializer(serializer);template.afterPropertiesSet();return template;}}
2.3 FastJson2JsonRedisSerializer 类 ,使用StringRedisSerializer来序列化和反序列化redis的key值.
/*** Redis使用FastJson序列化** @author dkmk*/
public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> {public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");static {ParserConfig.getGlobalInstance().setAutoTypeSupport(true);}@SuppressWarnings("unused")private ObjectMapper objectMapper = new ObjectMapper();private Class<T> clazz;public FastJson2JsonRedisSerializer(Class<T> clazz) {super();this.clazz = clazz;}@Overridepublic byte[] serialize(T t) throws SerializationException {if (t == null) {return new byte[0];}return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);}@Overridepublic T deserialize(byte[] bytes) throws SerializationException {if (bytes == null || by
http://www.dtcms.com/wzjs/832569.html

相关文章:

  • wordpress 群聊汉化版插件自己怎么优化网站
  • 海尔网站建设不足之处营销型网站建设风格设定包括哪些方面
  • 新手做自己的网站教程wordpress商店
  • 地方门户网站资讯该怎么做聊城网站制作需要多少钱
  • 用word怎么做网站西部数码怎么上传网站
  • 制作网站单页北京网站营销seo方案
  • 网页美工设计课程教案seo搜索工具栏
  • 怎么用大淘客做网站网站推广途径和方案
  • 做的好点的外贸网站南昌专业网站排名推广
  • 网站建设的代理如何做家具网站
  • 破解网站后台账号密码wordpress屏蔽右键
  • wordpress中英文网站移商网站建设
  • 有哪些网站是提供设计图片的网站服务器不稳定
  • 手机端企业网站源码下载百度云服务器一年多少钱
  • 网站开发 需要用到什么软件ui网页设计字体
  • 网站导航的作用百度58网络推广怎么做
  • 山东莱钢建设有限公司网站推广目标包括什么
  • 淘宝客购物网站源码沧州网站建设报价
  • 网站建设案例精粹微信网站建设和维护报价表
  • 网站分析百度具体的网站建设
  • 苏州信网网站建设技术有限公司wordpress怎么安装多说
  • 网站备案提交资料林州风景网站建设的目的
  • 手机微网站 模板乾安网站建设
  • wordpress网站接入qq重庆seo外包行者seo06
  • 帮别人做网站赚钱6南宁网站设计推广
  • 企业建站官网运营福建建设人才网
  • 贵州华瑞网站建设有限公司软件源码
  • 呼和浩特网站建设网络公司做时时网站要多少钱
  • 一学一做教育视频网站有哪些广州番禺网站制作公司哪家好
  • 电商设计素材网站有哪些优秀个人网站推荐