Introduction

When you are creating web apps with Java it is most likely that you will come across the Spring Framework. The Spring Framework is a very mature framework, which helps you to create applications very fast and does not depend on any Java Application Servers.

Using the framework you will most likely need to include properties files, because you are using some external configuration for example for the database connection.

Case 1: Including one properties file into your Spring app:

If you just need to include only one properties file, than you can use the following code.

<context:property-placeholder
	location="classpath:persistence.properties" />

To use this you will need to include the following schemas (and dependencies):

http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd

Case 2: Including more than one properties files into your Spring app:

If you would like to use more than on properties file in your Spring configuration, you would have to use the PropertyPlaceholderConfigurer. It allows you to pass a list of different paths to properties-files. This way it is also possible to configure for example the in-app-default-properties-files as default and external files - which override the configuration- at the end of the list.

Note: Last one - overwriting a key- wins.

<!-- If we need more than one property file, we just pass a list. -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:default.properties</value>
            <value>classpath:email.properties</value>
            <value>classpath:persistence.properties</value>
            <value>classpath:messages.properties</value>
        </list>
    </property>
</bean>

To use this you will need to include the following schemas (and dependencies):

http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd