loading .properties in spring-context.xml and persistence.xml

java, jpa, properties, spring, xml

Solution

You can reference external property files from a Spring bean definition file using a PropertyPlaceholderConfigurer. I don't think that will work for a JPA persistence.xml, although Spring's JPA support allows you to incorporate most, if not all, the content of persistence.xml into the beans file itself, in which case it would work fine.

Problem

is there a way to reference a .properties file in a spring-context.xml and a JPA persistence.xml? I think I've seen somewhere an example of this in spring context files, though I can't remember where that was. Maybe someone knows this? About the persistence.xml I am actually unsure if this works at all. My aim is to change some properties between development and distribution configuration. The idea I have currently is to replace all properties manually in the files via ant from a template config. Though there should be a better way to do this. :)

Original source