javajpa配置⽂件_springboot配置⽂件application.propert。。
1.application.properties配置jpa模板
spring.datasource.url=jdbc:mysql://localhost:3306/springboottest?
useunicode=true&characterencoding=utf8&servertimezone=utc
spring.datasource.username=yourname
spring.datasource.password=yourpassword
spring.datasource.sql.cj.jdbc.driver
#jpa setting
spring.jpa.database-platform=org.sql5innodbdialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
注意:url上⼀定要加上时区servertimezone=utc ,否则会报错。
当使⽤jpa访问数据库时,⼀定要设置数据库⽅⾔
2.application.properties配置druid数据源
springboot数据源配置的默认类型是at.jdbc.pool.datesource,为了使⽤druid连接池,可以将数据源类型更改为alibaba.druid.pool.druiddatasource。
修改数据源为druid的配置如下:
pe=com.alibaba.druid.pool.druiddatasource
配置参数设定数据源的⼯作⽅式,常⽤的数据源属性配置如下:
spring.datasource.initsize=5
spring.datasource.minidle=5
spring.datasource.maxactive=20
spring.datasource.maxwait=6000
#配置间隔多久才进⾏⼀次检测,检测需要关闭的空闲连接,单位是毫秒
spring.datasource.timebetweenevictionrunsmillis=60000
#配置⼀个连接在池中最⼩⽣存时间,单位是毫秒
spring.datasource.minevictableidletimemillis=300000
3.druid实现监控功能
druid简介:
druid是⼀个关系型数据库连接池,druid⽀持所有jdbc兼容的数据库,包括mysql,ororacle,derby,h2,sql server等。druid在监控、可扩展性、稳定性和性能⽅⾯有明显优势。通过druid提供的监控功能可以实时观察数据库连接池和sql查询的⼯作情况。使⽤druid连接池在⼀定程度上可以提⾼数据库的访问性能。
druid依赖:
com.alibaba
druid
1.1.10
监控功能的相关配置:
spring.datasource.filters=stat
spring.datasource.validationquery: select 1 from dual
stwhileidle: true
stonborrow: false
stonreturn: false
spring.datasource.poolpreparedstatements: true
spring.datasource.maxopenpreparedstatements: 20druid连接池配置详解
spring.datasource.filters: stat,wall,log4j
tionproperties: sql=true;druid.stat.slowsqlmillis=5000 #spring.datasource.useglobaldatasourcestat=true
希望与⼴⼤⽹友互动??
点此进⾏留⾔吧!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。