SpringBoot配置文件

本文最后更新于:2021年9月29日 凌晨

概览:SpringBoot配置文件,三个文件写法

properties文件

1
2
3
4
5
6
7
spring.datasource.url=jdbc:mysql://localhost:3306/springjob?useSSL=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
mybatis.mapper-locations=classpath:mapper/*.xml
# 注意:对应实体类的路径
mybatis.type-aliases-package=com.qfc.mybatisjob.entity

另一种

https://www.cnblogs.com/charlypage/p/11220755.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#server.port=80
logging.level.org.springframework=DEBUG
#springboot mybatis
#jiazai mybatis peizhiwenjian
mybatis.mapper-locations = classpath:mapper/*Mapper.xml
#mybatis.config-location = classpath:mybatis/sqlMapConfig.xml
#mybatis.type-aliases-package = com.demo.bean

#shujuyuan
spring.datasource.driver-class-name= com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/dss_wshop?useUnicode=true&characterEncoding=utf-8
spring.datasource.username = root
spring.datasource.password = root

spring.thymeleaf.prefix=classpath:/templates/

#禁止thymeleaf缓存(建议:开发环境设置为false,生成环境设置为true)
spring.thymeleaf.cache=false


#pagehelper分页插件配置 以下属性不加也可以实现分页功能
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql

yml文件

  • 来源:朝权的dubbo作业(h2 + lombok的日志)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
spring:
application:
name: qunar-address-provider
datasource:
url: jdbc:h2:mem:user_db;MODE=MySQL
driver-class-name: org.h2.Driver
username: root
password: root
# schema: classpath:db/user_schema.sql
# data: classpath:db/user_data.sql
jpa:
show-sql: true
h2:
console:
enabled: true
path: /h2
thymeleaf:
prefix: classpath:/templates/ #prefix:指定模板所在的目录
check-template-location: true #check-tempate-location: 检查模板路径是否存在
cache: false #cache: 是否缓存,开发模式下设置为false,避免改了模板还要重启服务器,线上设置为true,可以提高性能。
suffix: .html
#encoding: UTF-8
#content-type: text/html
mode: HTML5
logging:
config: classpath:logback-config.xml
server:
port: 81
  • 另一种
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 端口配置
server:
port: 8080

# 数据库配置
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis_homework?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
username: root
password: 123456
application:
name: mybatis-homework

# Mybatis
mybatis:
mapper-locations: classpath:mapper/*Mapper.xml
type-aliases-package: com.jiam.qunar.homework0805.bean
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

# 配置PageHelper
pagehelper:
helper-dialect: mysql

xml文件

1

yaml文件

1


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!