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

成都网站建设推广港哥熊掌号品牌包装设计制作

成都网站建设推广港哥熊掌号,品牌包装设计制作,静态网页设计教程,宿州百度seo排名软件前言 在分布式系统中#xff0c;共用组件的设计可以极大地提升代码复用性和维护性。Spring Cloud中将Redis共用到一个公共模块#xff08;common模块#xff09;是一个常见的设计实践#xff0c;这样可以让多个微服务共享相同的Redis配置和操作逻辑。本文将详细介绍如何在…前言 在分布式系统中共用组件的设计可以极大地提升代码复用性和维护性。Spring Cloud中将Redis共用到一个公共模块common模块是一个常见的设计实践这样可以让多个微服务共享相同的Redis配置和操作逻辑。本文将详细介绍如何在Spring Cloud中实现这一目标。 项目结构 首先定义项目的结构 spring-cloud-redis-common │ ├── common-module │ ├── src │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── common │ │ │ │ ├── RedisConfig.java │ │ │ │ ├── RedisService.java │ │ │ │ └── model │ │ │ │ └── CacheItem.java │ │ │ └── resources │ │ │ └── application.properties │ └── pom.xml │ └── service-module├── src│ ├── main│ │ ├── java│ │ │ └── com│ │ │ └── example│ │ │ └── service│ │ │ └── ServiceApplication.java│ │ └── resources│ │ └── application.properties└── pom.xml ​Common模块的实现 1. 定义Redis配置 在 common-module中创建 RedisConfig.java配置Redis连接 package com.example.common;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; import org.springframework.data.redis.core.StringRedisTemplate;Configuration public class RedisConfig {Beanpublic RedisTemplateString, Object redisTemplate(RedisConnectionFactory factory) {RedisTemplateString, Object template new RedisTemplate();template.setConnectionFactory(factory);return template;}Beanpublic StringRedisTemplate stringRedisTemplate(RedisConnectionFactory factory) {return new StringRedisTemplate(factory);} } ​2. 定义Redis操作服务 在 common-module中创建 RedisService.java提供Redis操作方法 package com.example.common;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service;import java.util.concurrent.TimeUnit;Service public class RedisService {Autowiredprivate RedisTemplateString, Object redisTemplate;public void set(String key, Object value, long timeout, TimeUnit unit) {redisTemplate.opsForValue().set(key, value, timeout, unit);}public Object get(String key) {return redisTemplate.opsForValue().get(key);}public void delete(String key) {redisTemplate.delete(key);} } ​3. 定义数据模型 在 common-module中创建 CacheItem.java定义数据模型 package com.example.common.model;import java.io.Serializable;public class CacheItem implements Serializable {private String id;private String value;// getters and setters } ​4. 配置文件 在 common-module的 resources目录下添加 application.properties spring.redis.hostlocalhost spring.redis.port6379 ​5. 添加依赖 在 common-module的 pom.xml中添加Spring Data Redis依赖 dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId/dependency /dependencies ​Service模块的实现 1. 添加依赖 在 service-module的 pom.xml中添加对 common-module的依赖 dependenciesdependencygroupIdcom.example/groupIdartifactIdcommon-module/artifactIdversion1.0.0/version/dependency /dependencies ​2. 使用Common模块中的Redis服务 在 service-module中创建 ServiceApplication.java使用 RedisService package com.example.service;import com.example.common.RedisService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication public class ServiceApplication implements CommandLineRunner {Autowiredprivate RedisService redisService;public static void main(String[] args) {SpringApplication.run(ServiceApplication.class, args);}Overridepublic void run(String... args) throws Exception {redisService.set(testKey, testValue, 1, TimeUnit.HOURS);System.out.println(Stored value: redisService.get(testKey));} } ​3. 配置文件 在 service-module的 resources目录下添加 application.properties以覆盖common模块中的配置 spring.redis.hostlocalhost spring.redis.port6379
http://www.w-s-a.com/news/10208/

相关文章:

  • 网站推广原则做网站的那个语言好
  • 潍坊网站建设怎样商品网站建设设计思路
  • 建网站公司是如何赚钱南昌营销网站公司哪家好
  • 淘宝客网站管理质量好网站建设费用
  • 网站建设教程搭建青岛中企动力做网站怎么样
  • wordpress最底部网站优化怎么弄
  • 二手市场网站建设的目的长沙ui设计公司
  • 微信公众号做留言网站wordpress详情页选择模板
  • php网站开发面向对象教程如何做分享赚钱的网站
  • 山东网站建设最便宜常州网站建站公司
  • 网站地图 seo中国建设招标网是私人网站吗
  • 高中作文网站全网营销有哪些平台
  • 网站构建建设制作平台上海搬家公司收费价目表
  • 成功案例展示网站做网站赚多少钱
  • 建设银行网站用什么字体网站建站后维护需要做哪些
  • 有哪些做平面设计好素材网站有哪些开网站建设
  • 国际交流网站平台有哪些筑建网
  • 网站程序是如何开发的江门市住房建设管理局网站
  • 网站建设一般需要几个步骤昵图网免费素材
  • 个人网站建设需求说明书微信域名防封在线生成
  • 专业网站建设的公司wordpress后台没有模板
  • 哈尔滨网站运营服务商制作外贸网站公司
  • 个人网站需要备案宁波网站推广工具
  • 苏州建设银行网站首页wordpress修改密码
  • 网站建设员工技能要求网站制作简单协议
  • 没有ipc备案的网站wordpress isux主题
  • 清远做网站电子商务网站建设需要的语言及特点6
  • 万州那家做网站c语言基础知识入门
  • 齐河网站建设公司价格网站建设包括什么
  • 论坛网站开发费用怎么把文件放到网站的根目录