Search code examples
springmavenapplicationcontext

How to use PropertyPlaceholderConfigurer to read from pom file inside another xml file?


i want to use PropertyPlaceholderConfigurer to read from pom file inside the applicationContext.xml file as follows:

<context:component-scan base-package="${project.groupId}"/>

taking in consideration that pom file has the following:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myapp</groupId>

here's the PropertyPlaceholderConfigurer configuration:

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:oauth_consumer.properties</value>
                <value>classpath:application.properties</value>
            </list>
        </property>

    </bean>

issue: PropertyPlaceholderConfigurer is not able to replace the value in applicationContext.xml.

please advise how to get that to work. thanks.


Solution

  • found the problem, the applicationContext was under src/main/webapp/WEB-INF but it had to be under src/main/resources in order to work.