This article will describe/discuss the Spring Framework.
Application-context.xml
The application-context.xml file is the starting point for your spring application. It allows you to define your imports and beans. Here is an example application-context.xml file:
application-context.xml
|
Above we are including the rotation-service.xml file which is as follows:
rotation-service.xml
|
In the above we have defined a bean with a name of tenantKeyRotationService which is of class com.irdeto.placodermi.vault.rotation.service.TenantKeyRotationService. We are also performing Constructor injection, injecting other beans which are defined in other application-context xml files. Here we are injecting tenantKeyDao into our tenantKeyRotationService class.
Loading Application Context programatically
Here we can see how to programatically load our spring application-context.xml file. In the following example, we are loading Beans.xml which defines our bean texteditor.
main class
|
Defining Profiles
We can define profiles for which beans would get instantiated.
application-context.xml
|
Above you should notice that we specify the beans tag and specify a profile called postgres. We can now tell our application or test to run using a list of profiles by adding the following env variable:
-Dspring.profiles.active=postgres,kms
Configuring Variables
We can define variables to use within our application by specifying the org.springframework.beans.factory.config.PropertyPlaceholderConfigurer bean in our application-context.xml file.
application-context.xml
|
In the above, we have defined a property file which would be found in resources/config/test-vault.properties and would look like the following:
|
Variables defined this way can be referenced in other application-context.xml files using the following syntax: ${property}. For example:
|