一、首先編寫 yaml 文件,建立項目所需的接口,在swagger.io官網上生成 spring boot項目;java
二、因爲生成的spring boot項目是公共類的因此還須要修改爲所需的項目名稱,主要修改四個地方,分別是:mysql
1) 包名;redis
2)Application ;spring
3)把 configuration/SwaggerDocumentationConfig.java中的包名修改成如今的包名sql
4) 修改pom.xml文件 其中Artifact和Project兩項api
spring boot + mysql + maven:app
因此須要在pom.xml中添加如下內容maven
<!-- mysql -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>spring-boot
在 application.properties 添加 mysql的驅動等url
springfox.documentation.swagger.v2.path=/api-docs
server.port=8089
spring.datasource.url = jdbc:mysql://192.168.0.1:3306/test
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName = com.mysql.jdbc.Driver
#pool
spring.datasource.max-idle=20
spring.datasource.max-wait=9000
spring.datasource.min-idle=10
spring.datasource.initial-size=5
spring.datasource.validation-query=SELECT 1
spring.datasource.test-on-borrow=false
spring.datasource.test-on-return=false
spring.datasource.test-while-idle=true
spring.datasource.time-between-eviction-runs-millis=600000
#spring.datasource.jdbc-interceptors=ConnectionState;SlowQueryReport(threshold=0)
# Specify the DBMS
#spring.jpa.database = MYSQL
# Show or not log for each sql query
spring.jpa.show-sql = false
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# stripped before adding them to the entity manager)
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
# REDIS (RedisProperties)
#spring.redis.database=redis
#spring.redis.host=192.168.0.1
#spring.redis.password= # server password
#spring.redis.port=6379
#spring.redis.pool.max-idle=8
#spring.redis.pool.min-idle=0
#spring.redis.pool.max-active=8
#spring.redis.pool.max-wait=-1
配置mysql鏈接池的緣由是,MySql 8小時重連問題 。當連續8小時沒有任何請求,mysql就會自動斷開鏈接。
到此須要的就基本配置完畢,接下來就能夠開始寫具體的代碼了。