Ciro Anacleto
Ciro Anacleto

Reputation: 119

Load properties in different Spring context

I have two Web applications: app-web1 and app-web2. app-web2 is a module of app-web1. Some configurations are needed by app-web2 that are in app-web1, like a application.properties. I am using spring PropertySourcesPlaceholderConfigurer to load the properties, but this just work in the context of app-web1. The app-web2's application-context.xml has an import resource from other project common to both Web projects.

Below is my bean in application-context-root.xml that is imported by others application-context:

<bean id="properties" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
  <property name="location" value="classpath*:config/application.properties"/>
  <property name="placeholderPrefix" value="$spring{" />
  <property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

My application.properties file is in web-app1 and I want to load this properties in app-web2 context.

How I can do this?

I am using:

Thanks in advance!

Upvotes: 2

Views: 1036

Answers (2)

Lovababu Padala
Lovababu Padala

Reputation: 2477

Relevant topic discussed here. SharedApplicationContext

And This

Upvotes: 1

leocborges
leocborges

Reputation: 4837

You can use resource-copy from maven-resources-plugin. See for more details: http://maven.apache.org/plugins/maven-resources-plugin/copy-resources-mojo.html

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.7</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/extra-resources</outputDirectory>
              <resources>          
                <resource>
                  <directory>src/non-packaged-resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

Upvotes: 0

Related Questions