How do you configure a Spring bean container (or application context) to load a Java property file?
JavaWorld article Smartly Load Your Properties explains how to load property files from the classpath using one of the following resource processing methods in the standard Java library:
ClassLoader.getResourceAsStream ("some/pkg/resource.properties");
Class.getResourceAsStream ("/some/pkg/resource.properties");
ResourceBundle.getBundle ("some.pkg.resource");
How can you do the same using a Spring bean container?
The Spring Framework Reference Documentation (2.5.x) gives two examples of how to load a property file into a bean container, one before the release of version 2.5 and a more concise way using the
<util:properties/>function that was introduced in version 2.5:Before version 2.5:
After version 2.5:
Note that in order to use
<util:properties/>, you must declare theutilnamespace and schema location in the preamble at the top of your Spring XML configuration file: