Book Image

Mockito for Spring

By : Sujoy Acharya
Book Image

Mockito for Spring

By: Sujoy Acharya

Overview of this book

Table of Contents (12 chapters)
Mockito for Spring
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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" jndi-name="java:comp/env/Datasource"
    resource-ref="true" cache="true" lookup-on-startup="false"
   proxy-interface="javax.sql.DataSource" />

In dev, we redefine it as follows:

<bean id="common-Datasource" 
  class="org.springframework...