数据库的基础配置(yml):
spring:
datasource:
driver-class-name: oracle.jdbc.driver.OracleDriver
url: jdbc:oracle:thin:@(DESCRIPTION=(FAILOVER=yes)(LOAD_BALANCE=yes)(ADDRESS=(PROTOCOL=TCP)(HOST=x.x.x.x)(PORT=1521))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=xxx)))
# url: jdbc:oracle:thin:@x.x.x.x:1521/xxx
username: xxx
password: xxx
mysql的配置:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/jtsys?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=CTT&characterEncoding=UTF-8
username: root
password: root
mybatis的基础配置
mybatis:
mapper-locations: mapper/**Mapper.xml
configuration:
map-underscore-to-camel-case: true
cache-enabled: true
Pagehelper分页
pagehelper:
helperDialect: oracle
reasonable: true
supportMethodsArguments: true
params: count=countSql
端口号配置
server:
port: 8091
servlet:
encoding:
charset: UTF-8
eureka的配置
eureka:
client:
service-url:
defaultZone: http://x.x.x.x:8761/eureka
配置服务名:
spring:
application:
name: XXXX
profiles:
active: dev //设置dev为加载环境
日志的配置
logging:
level:
xxxxxx(具体包名): debug
file:
path: /spring/log // 配置日志文件的存储路径
防止xss攻击
xss:
# 过滤开关
enabled: true
# 排除链接(多个用逗号分隔)
excludes: /system/notice/*
# 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/*
#线程池
thread:
pool:
keepAliveSeconds: 2000
maxPoolSize: 100
corePoolSize: 10
配置文件上传的文件大小上限为100M的限制:
spring:
servlet:
multipart:
max-request-size: 100MB
max-file-size: 100MB
nacos的配置
spring:
application:
name: novel-gateway
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848
file-extension: yml
group: ${spring.application.name}
namespace: edd2b089-4412-4c86-b187-0e9461d306d8
sentinel的启用
feign:
sentinel:
enabled: true
SpringBoot配置文件默认为application.和application-default.,如果通过spring.config.name属性指定了自定义配置文件名则加载读取指定的配置文件;扩展名有四个:.properties、.xml、.yml、.yaml;
1 在resouces目录下创建config文件夹,然后再在文件夹中创建一个application文件,发现config中的application.yml的加载是优先于resources目录下的application.yml 见截图
如果你在相同优先级位置(如在config文件夹中)同时有application.properties和application.yml,那么application.yml里面的属性就会覆盖application.properties里的属性
需要注意的是在工程根路径下或者根路径的config下面的配置文件,在工程打包时候不会被打包进去
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/auth?autoReconnect=true&useSSL=false
username: ${AUTH_DB_USER:root}
password: ${AUTH_DB_PWD:123456}
如上面的:$ 表示先从配置文件yml中或者启动命令中读取AUTH_DB_USER的值,如果没有读取到,就是用默认值root(其他变量类似)。好处是换一个新的环境时,不用改配置文件,直接在启动命令上指定值就可以