2 years ago

#18887

test-img

mandrake_2

Problems using multiple PropertySourcesPlaceholderConfigurer

Ok, I have been fighting this too long, time to ask for help. HELP!!!

I'm deploying an indipendent jar maven project that will be used as dependency into other projects. I need that this jar loads its own properties file ("versione.properties" released inside the jar) when the application that will use it, will start up but I want that the application doesn't care about it. This should be in charge on the lib. I want that who will use this lib, will have just to

  1. include the right dependency inside his pom.xml
  2. add <import resource="classpath*:*-context.xml" /> inside his spring app-context.xml to be sure to include also the lib-context.xml during the spring-context initialization

For this reason, the jar has its own spring lib-context.xml file as the following:

<context:component-scan base-package="it.eng.inps.comppsr" />

<bean id="propertyPlaceholderConfigurer2" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="ignoreResourceNotFound" value="false" />
    <property name="locations">
        <list>
            <value>classpath:versione.properties</value>
        </list>
    </property>
</bean>

<bean id="version" class="it.eng.inps.comppsr.util.Versione">
    <property name="buildVersion" value="${comppsrutil.build.version}"/>
    <property name="buildDate" value="${comppsrutil.build.timestamp}"/>
</bean>

As you can immagine, "versione.properties" file contains comppsrutil.build.version and comppsrutil.build.timestamp. During my tests, I've tried also <value>classpath*:versione.properties</value>, <value>classpath:/versione.properties</value> and <value>classpath:*/versione.properties</value> but with no luck.

This library is used by a web-service application (a war inside an ear file) and this application has got its own spring app-context.xml that loads it own properties file as described by the following code snippet

<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" depends-on="lookupPropertiesInitializer">
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    <property name="searchSystemEnvironment" value="true" />
    <property name="ignoreResourceNotFound" value="false" />
    <property name="locations">
        <list>
            <value>file:///#{lookupPropertiesInitializer.pathToProperties}</value>
            <value>classpath*:version.properties</value>
        </list>
    </property>
</bean>

<context:component-scan base-package="it.eng.inps.util, it.eng.inps.comppsr" />

<import resource="classpath*:*-context.xml" />

When I start the application (it runs inside JBoss EAP 7.3), I get this error: Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'comppsrutil.build.version' in value "${comppsrutil.build.version}"

So, it seems that something goes wrong within the lib initialization. If I rename the "versione.properties" file in "version.properties" (so with the same name used by the app properties file), this error desappear, I think, because it is loaded by the application PropertyPlaceholderConfigurer, so the lib property file is well located. For this reason I think that the bean propertyPlaceholderConfigurer2 defined inside lib-context.xml, doesn't work as I expected but I didn't understand why.

Does anyone give me any tips?

java

spring

properties-file

0 Answers

Your Answer

Accepted video resources