Multiple ways to specify the environment in which a Spring Boot project starts (profile)

–spring.profiles. Active =dev

Method 1: Specify when starting the Java package:

Java -jar -xMS256m -xmx256m./target/$(APP_NAME)-0.0.1 -snapshot.jar --spring.profiles. Active =$(SPRING_PROFILE)Copy the code

Mode 2: Specify when doker run:

docker rm -f $(APP_NAME) |true&&docker run --publish 5000:5000 -e SPRING_PROFILES_ACTIVE=$(SPRING_PROFILE) --name $(APP_NAME) $(APP_NAME) : 1.0Copy the code

Method 3: Use Docker Compose to define a Spring Profile

If DockerSwarm is used, or docker-comematery. yml is used to deploy docker images, Spring profiles can be passed through the environment tag of the docker-comematery. yml file. Such as:

. Version: "3" services: restful apis: image: RESTFUL apis :0.0.1 ports: - "8080:8080" Environment: - "SPRING_PROFILES_ACTIVE=dev" ...Copy the code