热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

20210317springbootyml文件mabatis、druid,完整配置:

springbootyml文件mabatis、druid,完整配置:spring:datasource:username:rootpassword:12

springboot yml文件mabatis、druid,完整配置:
spring:
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://localhost/springboot?characterEncoding=utf-8&useSSl=false
    driver-class-name: com.mysql.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    #监控统计拦截的filters
    filters: stat,wall,log4j
    #druid配置
    #配置初始化大小/最小/最大
    initialSize: 5
    minIdle: 5
    maxActive: 20
    #获取连接等待超时时间
    maxWait: 60000
    #间隔多久进行一次检测,检测需要关闭的空闲连接
    timeBetweenEvictionRunsMillis: 60000
    #一个连接在池中最小生存的时间
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    #打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
    poolPreparedStatements: false
    maxPoolPreparedStatementPerConnectionSize: 20
    # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
    connectionProperties:
      druid:
        stat:
          mergeSql: true
          slowSqlMillis: 5000 
#mybatis是独立节点,需要单独配置
mybatis:
  mapper-locations: classpath*:mapper/*.xml
  type-aliases-package: com.deceen.demo.entity
  configuration:
    map-underscore-to-camel-case: true

把原有的application.properties删掉。然后 maven -X clean install,或者通过Maven Project双击clean和install
(1)端口服务配置

  


1

2

3

4

5

#端口,项目上下文根

server:

  port: 8080

  servlet:

    context-path: /hotel

  


其中context-path: /hotel可以不用配置
如果配置,访问路径就是http://ip:port/hotel/
没有配置,访问路径就是http://ip:port/

(2)数据库配置

  

spring:datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=falseusername: rootpassword: rootjpa:hibernate:ddl-auto: updateshow-sql: trueredis:database: 0host: localhostport: 6379password:jedis:pool:max-active: 8max-wait: -1max-idle: 8min-idle: 0timeout: 0

 


(3)配置多个不同的profile,实现在不同的环境(比如开发、测试和生产环境)使用不同的配置变量。

  

# 默认的profile为dev,其他环境通过指定启动参数使用不同的profile,比如:
# 测试环境:java -jar my-spring-boot.jar --spring.profiles.active=test
# 生产环境:java -jar my-spring-boot.jar --spring.profiles.active=prod
spring:profiles:active: dev---
# 开发环境配置
spring:profiles: dev
mysql:ipPort: localhost:3306---
# 测试环境配置
spring:profiles: test
mysql:ipPort: ip:port---
# 生产环境配置
spring:profiles: prod
mysql:ipPort: ip:port

 


使用方法:
通过指定启动参数使用不同的profile
测试环境: java -jar my-spring-boot.jar --spring.profiles.active=test
生产环境: java -jar my-spring-boot.jar --spring.profiles.active=prod

(3)指定静态资源路径

 

spring:resources:#指定静态资源路径,默认为classpath:[/META-INF/resources/,/resources/, /static/, /public/]以及context:/static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/}

 

 

(4)热部署
在Springboot+Thymeleaf的开发过程中,默认情况下修改到任何代码都需要重新启动项目才能生效。使用spring.thymeleaf.cache和devtools来解决html热启动的问题
首先在pom.xml中配置



org.springframework.boot
spring-boot-devtools
runtime
true

 



注意:true只有设置为true时才会热启动,即当修改了html、css、js等这些静态资源后不用重启项目直接刷新即可。
然后修改application.yml

#热部署--静态资源立即生效
spring:#热部署--静态资源立即生效thymeleaf:cache: falseencoding: UTF-8mode: LEGACYHTML5prefix: classpath:/templates/suffix: .htmlcheck-template-location: true#热部署生效devtools:restart:enabled: true

 

  

如果需要在修改java文件后都能自动更新,则需要将原先的maven构建修改。
配置了true后在修改java文件后也就支持了热启动,不过这种方式是属于项目重启(速度比较快的项目重启),会清空session中的值,也就是如果有用户登陆的话,项目重启后需要重新登陆。





org.springframework.boot
spring-boot-maven-plugin


 

 





org.springframework.boot
spring-boot-maven-plugin


true



 

(5)时间配置

spring:jackson:#指定日期格式,比如yyyy-MM-dd HH:mm:ssdate-format: yyyy-MM-dd HH:mm:ss#指定日期格式化时区time-zone: GMT+8

 

 

(6)模板配置
springboot 中自带的页面渲染工具为thymeleaf 还有freemarker 这两种模板引擎 。



org.springframework.boot
spring-boot-starter-freemarker

  

spring:freemarker:suffix: .html #设定模板的后缀request-context-attribute: request #request访问requestcontent-type: text/htmlenabled: truecache: false #缓存配置template-loader-path: classpath:/templates/ #模板加载路径 按需配置charset: UTF-8 #编码格式settings:number_format: '0.##' #数字格式化,无小数点

 

(7)redis和shiro配置



org.springframework.boot
spring-boot-starter-data-redis


org.apache.shiro
shiro-spring
1.3.2

 

spring:redis:database: 0host: localhostport: 6379password:jedis:pool:max-active: 8max-wait: -1max-idle: 8min-idle: 0timeout: 0shiro:conf:domain:COOKIEPath: /successUrl: /indexloginView: /loginopenToken: falsesessionTimeout: 1800000algorithmName: md5hashIterations: 5#不拦截的路径sysanon:- /login- /regist#跨域配置allowedOrigins:- /**


推荐阅读
author-avatar
poohyxp
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有