spring boot + swagger + mysql + maven

1、首先编写 yaml 文件,创建项目所需的接口,在swagger.io官网上生成 spring boot项目;

2、由于生成的spring boot项目是公共类的所以还需要修改成所需的项目名称,主要修改四个地方,分别是:

1) 包名;

2)Application 

3)把 configuration/SwaggerDocumentationConfig.java中的包名修改为现在的包名

4) 修改pom.xml文件 其中Artifact和Project两项

spring boot + mysql + maven:

所以需要在pom.xml中添加以下内容

<!-- 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>

在 application.properties 添加 mysql的驱动等

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就会自动断开连接。

到此需要的就基本配置完毕,接下来就可以开始写具体的代码了。

posted @ 2016-07-22 11:31  奋斗中的青年  阅读(1114)  评论(0编辑  收藏  举报