How to specify spring.profiles.active when springboot starts
springboot startup specifies spring.profiles.active
Maven startup specifies Profile through -P,
such as mvn spring-boot:run -Ptest
But this is Maven's Profile.
If you want to specify spring.profiles.active of spring-boot,
spring-boot 1.x use mvn spring-boot:run -Drun.profiles=test ,
spring-boot 2.x uses mvn spring-boot:run -Dspring-boot.run.profiles=test.
If you use the command line to run the jar file directly, use java -jar -Dspring.profiles.active=test demo-0.0.1-SNAPSHOT.jar
If Use development tools to run the Application.java file to start,
then add parameters - -spring.profiles.active=test
At the same time, pay attention to the problem that the startup does not take effect:
In the linux centos 7 system, release the jar package
nohup java -Xmx256m -jar xxxx --spring.profiles.active=prod &
Every time it is started, the test environment is started
After various troubleshooting, it was finally discovered that the startup class does not exist Pass in the parameters args
SpringBoot activates profiles. Do you know several ways?
Multiple environments are one of the most common configuration isolation methods, and can be run according to different The environment provides different configuration information to deal with different business scenarios. SpringBoot supports multiple configuration isolation methods, and single or multiple configuration files can be activated.
How to activate Profiles
Activated profiles must create a corresponding configuration file in the project, in the format of application-{profile}.yml.
1. Command line method
The command line method is an external configuration method. When executing the java -jar command, you can use the –spring. Use profiles.active=test to activate the specified profiles list.
The usage method is as follows:
java -jar order-service-v1.0.jar --spring.profiles.active=dev &> order-service.log &
System variable method
1. Mac/Linux system configuration environment variable
Edit Environment variable configuration file /etc/profile, add an environment variable named SPRING_PROFILES_ACTIVE, as shown below:
spring environment activation
export SPRING_PROFILES_ACTIVE=dev
2. Windows system configuration environment variables
For how to configure environment variables, please refer to Java environment variable configuration. Create a new system environment variable named SPRING_PROFILES_ACTIVE and set the value of the variable to dev.
The system variable method is suitable for SpringBoot applications deployed in a unified environment under the system. For example, all applications deployed in a unified environment are prod environment applications.
Java system property mode
Java system property mode is also an external configuration method. When executing the java -jar command, it can be activated and specified through -Dspring.profiles.active=test. List of profiles.
The usage method is as follows:
java -Dspring.profiles.active=dev -jar order-service-v1.0.jar &> order-service.log &
Note: The -D method to set Java system properties must be defined before -jar.
Configuration file method
The configuration file method is the most commonly used method, but it is not very flexible and has great limitations. It is not recommended to use this method to activate the configuration file.
We only need to add configuration in the application.yml configuration file. The usage method is as follows:
spring: profiles: # 激活profiles active: dev
Priority
Command line method> Java System property mode> System variable mode> Configuration file mode
After testing, the command line mode has the highest priority, while the internal configuration file mode is the lowest.
Activate multiple profiles
If you need to activate multiple profiles, you can use commas to separate them, such as: - -spring.profiles.active=dev,test
Key points on the blackboard
Every application project will use a large number of configuration files or external configuration centers, and the activation of configuration information is an essential step and is particularly important.
It is recommended that you use system environment variables to activate the configuration of the specified profile. This method is relatively simple and can be used globally in the system (note: the global system means that all SpringBoot applications running under the system will use it. configuration), of course, it can also be specified individually using priority replacement rules.
The above is the detailed content of How to specify spring.profiles.active when springboot starts. For more information, please follow other related articles on the PHP Chinese website!

JVMmanagesgarbagecollectionacrossplatformseffectivelybyusingagenerationalapproachandadaptingtoOSandhardwaredifferences.ItemploysvariouscollectorslikeSerial,Parallel,CMS,andG1,eachsuitedfordifferentscenarios.Performancecanbetunedwithflagslike-XX:NewRa

Java code can run on different operating systems without modification, because Java's "write once, run everywhere" philosophy is implemented by Java virtual machine (JVM). As the intermediary between the compiled Java bytecode and the operating system, the JVM translates the bytecode into specific machine instructions to ensure that the program can run independently on any platform with JVM installed.

The compilation and execution of Java programs achieve platform independence through bytecode and JVM. 1) Write Java source code and compile it into bytecode. 2) Use JVM to execute bytecode on any platform to ensure the code runs across platforms.

Java performance is closely related to hardware architecture, and understanding this relationship can significantly improve programming capabilities. 1) The JVM converts Java bytecode into machine instructions through JIT compilation, which is affected by the CPU architecture. 2) Memory management and garbage collection are affected by RAM and memory bus speed. 3) Cache and branch prediction optimize Java code execution. 4) Multi-threading and parallel processing improve performance on multi-core systems.

Using native libraries will destroy Java's platform independence, because these libraries need to be compiled separately for each operating system. 1) The native library interacts with Java through JNI, providing functions that cannot be directly implemented by Java. 2) Using native libraries increases project complexity and requires managing library files for different platforms. 3) Although native libraries can improve performance, they should be used with caution and conducted cross-platform testing.

JVM handles operating system API differences through JavaNativeInterface (JNI) and Java standard library: 1. JNI allows Java code to call local code and directly interact with the operating system API. 2. The Java standard library provides a unified API, which is internally mapped to different operating system APIs to ensure that the code runs across platforms.

modularitydoesnotdirectlyaffectJava'splatformindependence.Java'splatformindependenceismaintainedbytheJVM,butmodularityinfluencesapplicationstructureandmanagement,indirectlyimpactingplatformindependence.1)Deploymentanddistributionbecomemoreefficientwi

BytecodeinJavaistheintermediaterepresentationthatenablesplatformindependence.1)Javacodeiscompiledintobytecodestoredin.classfiles.2)TheJVMinterpretsorcompilesthisbytecodeintomachinecodeatruntime,allowingthesamebytecodetorunonanydevicewithaJVM,thusfulf


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor
