Skip to main content

动态传参数

接下来我们在Springboot配置文件把数据库配置用spEL表达式替换 #配置数据库链接

spring.datasource.url = jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}?useUnicode=true&characterEncoding=utf8
#配置数据库用户名
spring.datasource.username = ${DB_USER}
#配置数据库密码
spring.datasource.password = ${DB_PASSWORD}

docker-compose.yml 配置我们的数据库参数

version: '3'
services:
web:
restart: always
depends_on:
- db
image: springboot-app-image
build: .
ports:
- 8080:8080
environment:
- DB_HOST=192.168.0.11
- DB_PORT=3306
- DB_USER=root
- DB_PASSWORD=123456
- DB_NAME=db
networks:
- credit-facility-net
deploy:
mode: replicated
replicas: 3
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
update_config:
parallelism: 1
delay: 10s