Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8365883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:46:18+00:00 2026-06-09T12:46:18+00:00

I am trying to configure a Spring configuration file with database information based on

  • 0

I am trying to configure a Spring configuration file with database information based on whether a certain Maven profile is active. I’ve seen pieces of answers to this but I’m having trouble putting it all together.

I have a Maven profile like this:

<profiles>
    <profile>
        <id>production</id>
        <activation>
            <property>
                <name>environment.type</name>
                <value>prod</value>
            </property>
        </activation>
    </profile>

    <profile>
        <id>development</id>
        <activation>
            <property>
                <name>environment.type</name>
                <value>dev</value>
            </property>
        </activation>

        <!-- Database properties for Spring -->
        <properties>
            <db.driver>oracle.jdbc.driver.OracleDriver</db.driver>
            <db.type>oracle</db.type>
            <db.host>192.168.0.0</db.host>
            <db.port>1521</db.port>
            <db.name>myDb</db.name>
            <db.url>jdbc:${db.type}:thin:@${db.host}:${db.port}:${db.name}</db.url>
        </properties>

And a settings.xml file like this:

<servers>
  <server>
    <id>development</id>
    <username>jsmith</username>
    <password>secret</password>
  </server>
</servers>

....

<profiles>
  <profile>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>

    <properties>
      <environment.type>dev</environment.type>
    </properties>
  </profile>
</profiles>

And in servlet-context.xml:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
    <property name="driverClassName">
        <value>${db.driver}</value>
    </property>

    <property name="url">
        <value>${db.url}</value>
    </property>

    <property name="username">
        <value>${db.username}</value>
    </property>

    <property name="password">
        <value>${db.password}</value>
    </property>

    <property name="maxActive">
        <value>10</value>
    </property>

    <property name="maxIdle">
        <value>1</value>
    </property>
</bean>

My question is basically, how do I get the Maven properties into the servlet-context.xml file? Do I need a .properties file? I know a little about filtering in Maven and PropertyPlaceholderConfigurer in Spring but I don’t know how to put them together — or do they go together? Or is there a simpler way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:46:19+00:00Added an answer on June 9, 2026 at 12:46 pm

    Using what I learned from the two answers and my research, I was able to get a development/production system, controlled by the pom, that sets the correct database values.

    First, in the pom, I created two profiles.

    <!-- Production and Development Profiles -->
    
    <profiles>
        <!-- Nike profile needs go here -->
        <profile>
            <id>production</id>
            <activation>
                <property>
                    <name>environment.type</name>
                    <value>prod</value>
                </property>
            </activation>
        </profile>
    
        <!-- Catalyst profile needs go here -->
        <profile>
            <id>development</id>
            <activation>
                <property>
                    <name>environment.type</name>
                    <value>dev</value>
                </property>
            </activation>
    
            <build>
    
                <!-- This holds the properties for the Spring context file.
                     Database values will be changes to development. -->
                <filters>
                    <filter>src/main/resources/dev.database.properties</filter>
                </filters>
    
                <resources>
    
                    <!-- This is the directory that holds the Spring context
                         file.  The entire folder is searched, so either no
                         other file should have place holders or you should
                         exclude other files from being filtered. -->
                    <resource>
                        <directory>src/main/webapp/WEBINF/</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
        </profile>
    </profiles>
    

    In the servlet-context.xml, in the WEBINF directory, I put place holders:

    <!-- For database, uses maven filtering to fill in placeholders -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${db.driver}" />
        <property name="url"             value="${db.url}" />
        <property name="username"        value="${db.username}" />
        <property name="password"        value="${db.password}" />
        <property name="maxActive">
            <value>10</value>
        </property>
        <property name="maxIdle">
            <value>1</value>
        </property>
    </bean>
    

    Then I created a properties file to sit in src/main/resources

    #
    # Development database properties file
    #
    db.driver=oracle.jdbc.driver.OracleDriver
    db.url=jdbc:oracle:thin:[USER/PASSWORD]@[HOST][:PORT]:SID
    db.username=jsmith
    db.password=s3cr3t
    

    I can then start Maven with

    mvn -P developement clean install
    

    or have a settings.xml that sets the correct profile for me:

    <settings>
      <profiles>
        <profile>
          <activation>
            <activeByDefault>true</activeByDefault>
          </activation>
    
          <properties>
            <environment.type>dev</environment.type>
          </properties>
        </profile>
      </profiles>   
    </settings>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to configure a class with Annotation based configuration in Spring 3, which
I was trying to configure spring 3.1 and hibernate. I have written a simple
I am trying to configure JMX console for my standalone Spring application. I have
I am trying to configure the CLIENTS table on my database such that if
We are trying to configure Spring JavaMailSender to work with Amazon's SES service using
I am trying to configure Spring Security in my simple application. Here is my
I'm trying to write a web application using Spring MVC. I have a configuration
I'm trying to configure ASP.NET MVC 2 RC and Spring .NET 1.3 to use
I'm trying out the whole convention over configuration thing with Spring MVC. Spring has
Trying to configure SQL Ce database, and get the following exception on BuildSessionFactory() .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.