2

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:

  • JBoss AS 7.1.1;
  • Java EE 7;
  • Spring 3.2.12;

Thanks in advance!

x80486
  • 6,627
  • 5
  • 52
  • 111
Ciro Anacleto
  • 109
  • 1
  • 11
  • Is `app-web1` a *module* or a *dependency* in/of `app-web2`? Or both? Probably this file isn't in `app-web2` classpath. – Bruno Ribeiro Jun 16 '15 at 22:01
  • @bruno, both are 2 .war files independents of each other. Concerning to maven they aren't dependencies each other. Both web projects has a dependency to a third project, the _core.jar_ in maven. The `application-context-root.xml` is in this .jar and this xml is imported as resource in `application-context.xml` of web-projects. – Ciro Anacleto Jun 17 '15 at 01:07
  • So `application.properties` is in `app-web1` and not in a shared project which both depends. Also, `app-web1` is packaged as `war` and isn't a `app-web2` dependency, is it? So, how this property file is in `app-web2` classpath? Also: `web-app1` and `app-web1` is the same thing, right? Maybe you should consider update your question with more detail. – Bruno Ribeiro Jun 17 '15 at 12:03
  • @bruno,application.properties isn't in `app-web2` classpath, only in `app-web1`. What I'm looking for is a way to access the values in propertie file that are in other context. I will update my question with more details. – Ciro Anacleto Jun 17 '15 at 14:35

2 Answers2

1

Relevant topic discussed here. SharedApplicationContext

And This

Community
  • 1
  • 1
Lovababu Padala
  • 2,415
  • 2
  • 20
  • 28
0

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>
leocborges
  • 4,799
  • 5
  • 32
  • 38
  • Thanks for your answer. I already use this plugin. But isn't this what I need. The propertie are copied to artifact assembled. What I need is load the value inside the propertie file inside the .war in Jboss in runtime using spring properties. – Ciro Anacleto Jun 16 '15 at 21:16