me1111
me1111

Reputation: 1157

Accessing properties file from another module context

I use maven. My web application contains two modules and each has it's own spring context. First is packed to jar, the second one to war. The second one uses first module's jar and calls it's methods.

I need to add property file, which will be used by first module (via spring context). The main issue is that I should be able to access/edit this property file after war deployment.

How can I provide such a property file, that will be used in first jar module and can be changed after war module deployment?

Thanks.

Upvotes: 3

Views: 4839

Answers (1)

Marcel Stör
Marcel Stör

Reputation: 23535

Sorry, don't see the problem, you need to describe that better. From what I understood this is the way to go:

  1. place a.properties in src/main/resources in the JAR module
  2. use a PropertyPlaceholderConfigurer to make the properties available in the Spring context
  3. it'll be packed in root of the JAR
  4. the JAR ends up in WEB-INF/lib of the WAR which again is "root of the classpath" so to speak

Update, 2013-06-09

(question was updated based on comments to initial answer above)

Essentially what you seem to be looking for (still not quite sure) is how to load properties from a properties file that is not packaged with your WAR/JAR.

In this case you can skip all of the above steps except 2.

  1. Use a PropertyPlaceholderConfigurer and specify the location of the file as classpath*:a.properties (see below)
  2. Place a.properties anywhere on the classpath outside the WAR file.

Warning! Of course you can now edit the properties independently from releasing the WAR file but since Spring initializes the beans on application start and since all beans are singletons by default changes to the properties file won't become effective until you restart the app.

XML example

<bean class="....PropertyPlaceholderConfigurer">
  <property name="location" value="classpath*:a.properties" />

Upvotes: 2

Related Questions