您的位置:首页 > 数据库 > Redis

IDEA springboot集成ehcache单节点和redis集群

2018-03-18 19:21 786 查看
1.     IDEA springboot集成ehcache和redis
1.1  集成redis(1)     新建springboot项目




Next

Next

Finish 等待加载工程所需依赖,如果加载无差错项目可以直接运行


 
(2)     添加redis所需要的包(在pom.xml)
http://mvnrepository.com/搜索redis
选着spring data redis
<!--https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis-->
<dependency>
    <groupId>org.springframework.data</groupId>
   <artifactId>spring-data-redis</artifactId>
   <version>2.0.5.RELEASE</version>
</dependency>
(3)     编写配置文件(application.properties)server.port=80  (服务端口号)
spring.redis.database
=0 (redis数据库选择,redis数据库默认情况下有十六个,可以通过配置文件增加数量,对于单机情况下才会有数据库的概念,集群环境下是没有数据库概念的,会随机存到所有的数据库下)
spring.redis.host
=localhost  (redis服务地址)
spring.redis.port
=6379(redis端口号,可以在配置文件修改)
 
(4)     使用注解开启redis服务



(5)     编写redis配置类,把redistemplete注入容器
 


(6)     编写测试类



1.2  Springboot 集成redis集群
(1)     Redis集群使用的是Jedis依赖,先引入jedis依赖
<!--jedis依赖-->
        <dependency>
           <groupId>redis.clients</groupId>
           <artifactId>jedis</artifactId>
           <version>2.9.0</version>
       </dependency>
(2)     编写Jedis配置文件



(3)     配置读取



(4)     别写配置类获取集群链接,将链接对象注入容器



(5)     编写测试类





1.3  Springboot 集成 ehcache
(1)     添加依赖包(2)    <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-configuration-processor</artifactId>
   <optional>true</optional>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-cache</artifactId>
   <version>1.4.2.RELEASE</version>
</dependency>(3)     编写配置文件application.propertise



 在resource下添加ehcache.xml编写配置文件



(4)     使用注解编写缓存类主要使用@Caehcache
          标注:部分有借鉴如有侵权请联系244774097@qq.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: