SpringBoot2.3,使用MySQL数据库,通过JPA实现ORM,再用Redis实现数据库的缓存。
代码实现:
pom.xml
<!-- 集成redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.48</version>
</dependency>
<!-- 集成data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
application.properties
#数据库索引(默认为0)
spring.redis.database=0
spring.redis.host=localhost
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=
#连接超时时间
spring.redis.timeout=10000
#最大连接数
spring.redis.jedis.pool.max-active=8
#最大阻塞等待时间(负数表示没限制)
spring.redis.jedis.pool.max-wait=-1
#最大空闲
spring.redis.jedis.pool.max-idle=8
#最小空闲
spring.redis.jedis.pool.min-idle=0
#==================mysql========================
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/woxiang_test?setUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.username=root
spring.datasource.password=000000
#====================jps=