springboot之druid

#-----------h2数据库配置 http://localhost:8080/h2-console
#---控制台配置
spring.h2.console.path=/h2-console
spring.h2.console.enabled=true
spring.h2.console.settings.web-allow-others=true
#-----驱动配置 druid https://github.com/alibaba/druid
spring.datasource.url = jdbc:h2:file:F:/ideaPro/demo1/src/main/resources/db/testdb;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
#spring.datasource.url = jdbc:h2:file:~/.h2/testdb
spring.datasource.username = sa
spring.datasource.password = sa
spring.datasource.driverClassName = org.h2.Driver
# 配置初始化大小、最小、最大
spring.datasource.druid.initial-size=5
spring.datasource.druid.max-active=20
spring.datasource.druid.min-idle=5
# 配置获取连接等待超时的时间 毫秒
spring.datasource.druid.max-wait=60000
spring.datasource.druid.validation-query=SELECT 1
spring.datasource.druid.test-on-borrow=false
spring.datasource.druid.test-on-return=false
spring.datasource.druid.test-while-idle=true
######Druid监控配置######
#下面配置说明请参考Druid Github Wiki,配置_配置WebStatFilter
spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*
#下面配置说明请参考Druid Github Wiki,配置_StatViewServlet配置
spring.datasource.druid.stat-view-servlet.loginUsername=druid
spring.datasource.druid.stat-view-servlet.loginPassword=druid
#mapper文件扫描
mybatis.mapperLocations = classpath*:/mapper/*.xml

pom dependency

<!-- 内存数据库h2-->
<dependency>
   <groupId>com.h2database</groupId>
   <artifactId>h2</artifactId>
   <scope>runtime</scope>
</dependency>
<!--druid-->
<dependency>
   <groupId>com.alibaba</groupId>
   <artifactId>druid-spring-boot-starter</artifactId>
   <version>1.1.2</version>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--springboot mapper文件扫描支持-->
<dependency>
   <groupId>org.mybatis.spring.boot</groupId>
   <artifactId>mybatis-spring-boot-starter</artifactId>
   <version>1.1.1</version>
</dependency>

Then you can directly start your project

The h2 database provides a web page, browser input: http://localhost:8080/h2-console   

h2-console is the property of spring.h2.console.path  

druid also provides a web page with database monitoring, browser input:  http://localhost:8080/druid

Account password: spring.datasource.druid.stat-view-servlet.loginUsername=druid

                  spring.datasource.druid.stat-view-servlet.loginPassword=druid

Of course, those who are not used to h2 can also be changed to mysql

#mysql jdbc
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.druid.url=jdbc:mysql://your IP:3306/database name?useUnicode=true&characterEncoding=UTF8&autoReconnect=true&rewriteBatchedStatements=TRUE&zeroDateTimeBehavior=convertToNull

zeroDateTimeBehavior=convertToNull: The time type without assignment is converted to null. If there is no this attribute, jpa may report an error when adding data.

pom.xml replace h2 with mysql driver 

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

Oh, #mapper文件扫描
mybatis.mapperLocations = classpath*:/mapper/*.xml

这个是扫描mapper文件的 mapper 是要在 resources 下创建的

 

 Finally, if you need to buy a server to play, please poke → 

https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=tqpvz8yl to
receive coupons.

Guess you like

Origin blog.csdn.net/qq_36338555/article/details/83218179