Spring外部化配置:JSON应用程序属性
当应用程序启动时,任何spring.application.json
或SPRING_APPLICATION_JSON
属性都会被解析并添加到Environment
中。
1
| $ SPRING_APPLICATION_JSON='{"my":{"name":"test"}}' java -jar myapp.jar
|
如果是docker-compose
可以直接设置环境变量
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| version: '3.4' services: serve: image: go-view-service restart: always ports: - "${SERVICE_APP_PORT}:8080" volumes: - ${SERVICE_RESOURCE_FILE_PATH}:/data/files - ${SERVICE_APP_WAR_PATH}:/app.war environment: SPRING_APPLICATION_JSON: '{"fuce":{"default-base-dir":"/data/files", "upload_img_url": "http://192.168.1.241:8081/static/file_upload/"}}' SPRING_DATASOURCE_DRUID_MASTER_URL: 'jdbc:mysql://192.168.1.241:3307/go-view?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false' SPRING_DATASOURCE_DRUID_MASTER_USERNAME: greatsql SPRING_DATASOURCE_DRUID_MASTER_PASSWORD: abc123
|
数据库配置也可以用环境变量SPRING_DATASOURCE_DRUID_MASTER
配置