Spring Boot:搭建一个简单的用户系统(一) - 环境搭建
一.用户系统需要哪些接口
我们接口角度看,一个用户系统需要如上图所示的接口,接下来就开始准备工作;
二.数据库安装
本文用的数据库为mysql,具体安装过程就不写了,附一篇博文: mysql可视化工具推荐navicat for mysql;
三.SpringBoot数据库配置
- pom.xml配置
<!-- 数据库相关 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
- application.properties
#数据库配置 spring.datasource.url=jdbc:mysql://localhost:3306/数据库名 spring.datasource.username=用户名 spring.datasource.password=密码 spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.jpa.properties.hibernate.hbm2ddl.auto=update spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.show-sql=true
三.redis安装
除了数据库,还用到了redis,安装过程也不写了,附一篇博文自己看: redis可视化工具推荐:rdm;
- pom.xml配置
<!-- redis相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
- application.properties
#Redis数据库索引(默认为0) spring.redis.database=0 # Redis服务器地址 spring.redis.host=127.0.0.1 # Redis服务器连接端口 spring.redis.port=6379 # Redis服务器连接密码(默认为空) spring.redis.password= # 连接池最大连接数(使用负值表示没有限制) 默认 8 spring.redis.lettuce.pool.max-active=8 # 连接池最大阻塞等待时间(使用负值表示没有限制) 默认 -1 spring.redis.lettuce.pool.max-wait=-1 # 连接池中的最大空闲连接 默认 8 spring.redis.lettuce.pool.max-idle=8 # 连接池中的最小空闲连接 默认 0 spring.redis.lettuce.pool.min-idle=0
四.数据库建表
五.注意点
- 有时候maven项目拉取失败,怎么叫失败呢,点击下图maven->Dependencies,如果有红色✘,则没有拉去成功,需要查看下你的maven源,如何查看呢; settings.xml就是maven项目拉取的源地址;
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
建议国内的改为aliyun的镜像,速度快不少,而且会减少失败的频率;
工欲善其事必先利其器,把mysql,redis和可视化工具搭建好后,就可以开始接口开发了。
