

The application is very security-centric but it doesn't neglect any features, ease of use or functionality. We all know the internet is not always safe and it's important to have our online conversations and file shares as secure as possible. QTox is a very powerful file-sharing and instant messaging application that focuses on security and ease of use. 8.4.A very secure file sharing and instant messaging tool That is, if some property, say my.prop, occurs once more at the end in the above example, the endmost value will be considered. This file is read by Spring Boot in top to bottom order. So now, we can specify the dev and production properties in the same application.properties: my.prop=used-always-in-all-profiles Starting version 2.4, Spring Boot has extended its support for multi-document files for properties files in addition to previously supported YAML. To further simplify defining properties for separate environments, we can even club all the properties in the same file and use a separator to indicate the profile. In this way, we can easily provide different configurations for different environments. Then we can configure the same properties for the dev profile in the application-dev.properties file, to use an in-memory H2 database: -class-name=org.h2.Driver In the application-production.properties file, we can set up a MySql data source: -class-name=.jdbc.Driver properties files only for the specified profile.įor example, we can configure different data sources for dev and production profiles by using two files named application-dev.properties and application-production.properties: Spring Boot will automatically load the properties in an application.properties file for all profiles, and the ones in profile-specific. Now, if no profiles are active, our activeProfile will just contain an empty string.Īnd if we want to access the list of them just like in the previous example, we can do it by splitting the activeProfile variable: public class ProfileManager String activeProfiles įor (String profileName : activeProfiles.split(",")). In order to avoid this, we can define a default value: String activeProfile This would result in an IllegalArgumentException owing to the missing placeholder for injecting into the variable.
Qtox loading a profile code#
With our code above, the absence of an active profile would prevent the application context from being created. However, we should consider what would happen if there is no active profile at all.

Here, our activeProfile variable will contain the name of the profile that is currently active, and if there are several, it'll contain their names separated by a comma. It also applies the value prod for this application when it is String activeProfile This command will package the application for prod profile.

Its value will be used to replace the placeholder in application.properties: we need to enable resource filtering in pom.xml: Īnd append a -P parameter to switch which Maven profile will be applied: mvn clean package -Pprod In every Maven profile, we can set a property: Spring profiles can also be activated via Maven profiles, by specifying the configuration property.
