如果使用的是redis2.x,在项目中使用客户端分片(Shard)机制。
如果使用的是redis3.x中的集群,在项目中使用jedisCluster。
1、项目结构
2、pom.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
5 <modelVersion>4.0.0</modelVersion>
6
7 <groupId>com.xxx</groupId>
8 <artifactId>myboot</artifactId>
9 <version>1.0-SNAPSHOT</version>
10
11 <properties>
12 <java.version>1.8</java.version><!-- 官方推荐 -->
13 </properties>
14 <!-- 引入spring-boot-starter-parent做parent是最好的方式,
15 但是有时我们可能要引入我们自己的parent,此时解决方式有两种:
16 1)我们自己的parent的pom.xml的parent设为spring-boot-starter-parent(没有做过验证,但是感觉可行)
17 2)使用springboot文档中的方式:见spring-boot-1.2.5-reference.pdf的第13页
18 -->
19 <parent>
20 <groupId>org.springframework.boot</groupId>
21 <artifactId>spring-boot-starter-parent</artifactId>
22 <version>1.2.5.RELEASE</version>
23 </parent>
24
25 <!-- <dependencyManagement>
26 <dependencies>
27 <dependency>
28 Import dependency management from Spring Boot
29 <groupId>org.springframework.boot</groupId>
30 <artifactId>spring-boot-dependencies</artifactId>
31 <version>1.2.5.RELEASE</version>
32 <type>pom</type>
33 <scope>import</scope>
34 </dependency>
35 </dependencies>
36 </dependencyManagement> -->
37
38 <!-- 引入实际依赖 -->
39 <dependencies>
40 <dependency>
41 <groupId>org.springframework.boot</groupId>
42 <artifactId>spring-boot-starter-web</artifactId>
43 </dependency>
44 <dependency>
45 <groupId>redis.clients</groupId>
46 <artifactId>jedis</artifactId>
47 </dependency>
48 <dependency>
49 <groupId>com.alibaba</groupId>
50 <artifactId>fastjson</artifactId>
51 <version>1.1.15</version>
52 </dependency>
53 <dependency>
54 <groupId>org.apache.commons</groupId>
55 <artifactId>commons-lang3</artifactId>
56 <version>3.3.2</version>
57 </dependency>
58 </dependencies>
59
60 <build>
61 <plugins>
62 <!-- 用于将应用打成可直接运行的jar(该jar就是用于生产环境中的jar) 值得注意的是,如果没有引用spring-boot-starter-parent做parent,
63 且采用了上述的第二种方式,这里也要做出相应的改动 -->
64 <plugin>
65 <groupId>org.springframework.boot</groupId>
66 <artifactId>spring-boot-maven-plugin</artifactId>
67 </plugin>
68 </plugins>
69 </build>
70 </project>