Configuring Spring profiles
Spring 3.1 introduced a feature called profiles. Profiles allow you to build one package that can be deployed in all environments, such as dev, test, prod, perf, and so on.
If we define a system property, spring.profiles.active
, or annotate a test class with @ActiveProfiles
and set the active profile names, Spring loads the beans from the context where the profile name matches or no profile name is defined. We can create different beans depending on the profile name using an XML configuration or the @Profile
annotation.
Suppose you have a dev environment and a prod environment; you use a JNDI lookup for DataSource
in prod, but in dev, you build DataSource
, as in the following snippet:
<jee:jndi-lookup id="common-Datasource" ...
Get Mockito for Spring now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.