Sometimes we may need to have some conditional statement in Spring XMl config depending upon some variables value.
Think of a situation when you are using JPA in your application and your application may have two persistence units in Spring XML config file and you need to connect to one of them depending upon the environments. For example, when you write code in your local system and want to test the application then you do not want to connect to the live database but you want to connect to in-memory database such as H2 or Derby or any other in-memory database due to having some constraints connecting from local system and when you deploy your code into other environments such as Dev, SIT, UAT, PROD then only you want to connect to the live database. So in such situtationyou may have two persistence units one for local and other for all other environments with the same schema. Therefore you want to pass a VM argument that will take your environment value and will connect to the appropriate persistence unit. Continue reading “Conditional Statement in Spring Config”