Spring boot + swagger + MySQL + maven

Source: Internet
Author: User
Tags mysql connection pool

1, first write the Yaml file, create the interface required for the project, and generate the Spring boot project on the Swagger.io website;

2, because the generated spring boot project is public class, it also needs to be modified to the desired project name, mainly modify four places, namely:

1) package name;

2) Application;

3) Change the package name in Configuration/swaggerdocumentationconfig.java to the current package name

4) Modify the Pom.xml file where artifact and project two items

Spring boot + mysql + maven:

So you need to add the following in 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>

Add MySQL driver in application.properties, etc.

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

The reason for configuring the MySQL connection pool is that MySQL has a8-hour reconnection problem . When there is no request for 8 consecutive hours, MySQL will automatically disconnect.

This requires a basic configuration, and then you can start writing the specific code.

Spring boot + swagger + MySQL + maven

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.