springboot配置文件很强大、也丰富,“约定优于配置”,只需做少量的配置,其它采用默认的就行。
application.properties(传统),application.yml(重点)
服务器端口配置
server:
port: 8080
日志配置
logging:
level:
root: info
com.jcj.mydemo: warn
file:
name: logs/system.log
JPA配置
spring:
jpa:
hibernate:
ddl-auto: update
show-sql: true
数据库连接池配置
自Druid1.1.10版本以后,完全基于yml就能让Druid运行起来
要做的工作:
1)pom.xml增加jpa、Mysql、Druid的jar包依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
2)在配置文件中增加配置参数
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/goodswarndb?serverTimezone=UTC&useSSL=false
username: root
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: 5
min-idle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
filters: stat,wall,slf4j
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
web-stat-filter:
enabled: true
url-pattern: "/*"
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
stat-view-servlet:
url-pattern: "/druid/*"
allow: 127.0.0.1,192.168.31.76
deny: 192.168.1.73
reset-enable: false
login-username: admin
login-password: admin123456
环境激活
设:有application-dev.yml、application.yml-pro、application.yml
spring:
profiles:
active: dev
thymeleaf配置
一般情况下,无需在yml中进行配置,采用其默认配置就很好,thymeleaf的默认配置如下:
spring.thymeleaf.cache
spring.thymeleaf.check-template-location
spring.thymeleaf.content-type
spring.thymeleaf.enabled
spring.thymeleaf.encoding
spring.thymeleaf.excluded-view-names
spring.thymeleaf.mode
spring.thymeleaf.prefix
spring.thymeleaf.suffix
spring.thymeleaf.template-resolver-order
spring.thymeleaf.view-names
resource配置
Resource是指资源相关的配置,一般情况下,无需在yml中进行配置,采用其默认配置就很好,默认配置如下:
spring.resources.add-mappings
spring.resources.cache-period
spring.resources.chain.cache
spring.resources.chain.enabled
spring.resources.chain.html-application-cache
spring.resources.chain.strategy.content.enabled
spring.resources.chain.strategy.content.paths
spring.resources.chain.strategy.fixed.enabled
spring.resources.chain.strategy.fixed.paths
spring.resources.chain.strategy.fixed.version
spring.resources.static-locations
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)