birdy
birdy

Reputation: 9646

How to have different context config files for different environments in spring MVC

On my local machine I'm developing using a certain db (sql server), however, when I deploy to the development environment we are running mysql. So everytime before deploying I have to change certain properties in the config file. Properties pertaining to the datasource:

<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://127.0.0.1:3306/mydb" />
    <property name="username" value="myuname" />
    <property name="password" value="mypwd"/>   
</bean>

Is there a way in spring mvc to have different config files for different environments? If so, how would I go about triggering the correct xml for the right environment.

Upvotes: 0

Views: 485

Answers (2)

NimChimpsky
NimChimpsky

Reputation: 47300

spring mvc to have different config files for different environments?

we store database connection settings in a properties file in tomcat, each tomcat instalaltion then has its own specific db connection. Eg, a local dev box connects to the local DB server, the UAT server connects to UAT ... and so on.

then in app context we have :

<context:property-placeholder location="file:${catalina.home}/conf/database_UAT.properties"
                                  ignore-unresolvable="true"/>

So where app gets deployed determines its DB connection.

Upvotes: 1

Jigar Parekh
Jigar Parekh

Reputation: 6283

i think having different config files for just this requirement is not an good idea. you should externalize db configuration in properties file with two different set, one for dev and second for production. and then use spring EL in configuration file to decide which one to use.

Refer to spring EL documentation for more detail

Upvotes: 0

Related Questions