yml文件配置mysql表大小写_springboot常用配置(yml文件)
(1)端口服務(wù)配置
server:
port: 8080 #端口號(hào)
servlet:
context-path: /main #項(xiàng)目訪問路徑
(2)數(shù)據(jù)庫配置
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: root
jpa:
hibernate:
ddl-auto: update
show-sql: true
redis:
database: 0
host: localhost
port: 6379
password:
jedis:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
timeout: 0
(3)配置多個(gè)不同的profile,實(shí)現(xiàn)在不同的環(huán)境(比如開發(fā)、測試和生產(chǎn)環(huán)境)使用不同的配置變量。
# 默認(rèn)的profile為dev,其他環(huán)境通過指定啟動(dòng)參數(shù)使用不同的profile,比如:
# 測試環(huán)境:java -jar my-spring-boot.jar --spring.profiles.active=test
# 生產(chǎn)環(huán)境:java -jar my-spring-boot.jar --spring.profiles.active=prod
spring:
profiles:
active: dev
---
# 開發(fā)環(huán)境配置
spring:
profiles: dev
mysql:
ipPort: localhost:3306
---
# 測試環(huán)境配置
spring:
profiles: test
mysql:
ipPort: ip:port
---
# 生產(chǎn)環(huán)境配置
spring:
profiles: prod
mysql:
ipPort: ip:port
使用方法:
通過指定啟動(dòng)參數(shù)使用不同的profile
測試環(huán)境: java -jar my-spring-boot.jar --spring.profiles.active=test
生產(chǎn)環(huán)境: java -jar my-spring-boot.jar --spring.profiles.active=prod
在配置文件中指定 spring.profiles.active=dev
虛擬機(jī)參數(shù)
?-Dspring.profiles.active=dev
springboot 啟動(dòng)會(huì)掃描以下位置的application.properties或者application.yml文件作為Spring boot的默認(rèn)配置文件
–file:./config/
–file:./
–classpath:/config/
–classpath:/
優(yōu)先級(jí)由高到底,高優(yōu)先級(jí)的配置會(huì)覆蓋低優(yōu)先級(jí)的配置
SpringBoot會(huì)從這四個(gè)位置全部加載主配置文件,互補(bǔ)配置;
項(xiàng)目打包好以后,我們可以使用命令行參數(shù)的形式,啟動(dòng)項(xiàng)目的時(shí)候來指定配置文件的新位置;指定配置文件和默認(rèn)加載的這些配置文件共同起作用形成互補(bǔ)配置;
java -jar spring-boot-02-config-02-0.0.1-SNAPSHOT.jar --spring.config.location=G:/application.properties
(4)指定靜態(tài)資源路徑
spring:
resources:
#指定靜態(tài)資源路徑,默認(rèn)為classpath:[/META-INF/resources/,/resources/, /static/, /public/]以及context:/
static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/}
(5)熱部署
在Springboot+Thymeleaf的開發(fā)過程中,默認(rèn)情況下修改到任何代碼都需要重新啟動(dòng)項(xiàng)目才能生效。使用spring.thymeleaf.cache和devtools來解決html熱啟動(dòng)的問題
首先在pom.xml中配置
org.springframework.boot
spring-boot-devtools
runtime
true
注意:true只有設(shè)置為true時(shí)才會(huì)熱啟動(dòng),即當(dāng)修改了html、css、js等這些靜態(tài)資源后不用重啟項(xiàng)目直接刷新即可。
然后修改application.yml
#熱部署--靜態(tài)資源立即生效
spring:
#熱部署--靜態(tài)資源立即生效
thymeleaf:
cache: false #是否開啟模板緩存,默認(rèn)true
encoding: UTF-8 #指定模板的編碼,默認(rèn)為: UTF-8
mode: HTML #指定模板的模式,具體查看StandardTemplateModeHandlers,默認(rèn)為: HTML5
prefix: classpath:/templates/ #前綴
suffix: .html #后綴
check-template-location: true #是否檢查模板路徑是否存在,默認(rèn)true
servlet:
content-type: text/html #響應(yīng)類型,指定Content-Type,默認(rèn)為: text/html
#熱部署生效
devtools:
restart:
enabled: true
(6)時(shí)間配置
spring:
jackson:
#指定日期格式,比如yyyy-MM-dd HH:mm:ss
date-format: yyyy-MM-dd HH:mm:ss
#指定日期格式化時(shí)區(qū)
time-zone: GMT+8
(7)模板配置
springboot 中自帶的頁面渲染工具為thymeleaf 還有freemarker 這兩種模板引擎 。
org.springframework.boot
spring-boot-starter-freemarker
spring:
freemarker:
suffix: .html #設(shè)定模板的后綴
request-context-attribute: request #request訪問request
content-type: text/html
enabled: true
cache: false #緩存配置
template-loader-path: classpath:/templates/ #模板加載路徑 按需配置
charset: UTF-8 #編碼格式
settings:
number_format: '0.##' #數(shù)字格式化,無小數(shù)點(diǎn)
(8)redis和shiro配置
org.springframework.boot
spring-boot-starter-data-redis
org.apache.shiro
shiro-spring
1.3.2
spring:
redis:
database: 0
host: localhost
port: 6379
password:
jedis:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
timeout: 0
shiro:
conf:
domain:
cookiePath: /
successUrl: /index
loginView: /login
openToken: false
sessionTimeout: 1800000
algorithmName: md5
hashIterations: 5
#不攔截的路徑
sysanon:
- /login
- /regist
#跨域配置
allowedOrigins:
- /**
總結(jié)
以上是生活随笔為你收集整理的yml文件配置mysql表大小写_springboot常用配置(yml文件)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win10怎么把用户名改成英文 win1
- 下一篇: centos的mysql命令,Cento