Spring Circular placeholder reference while running an executable jar

Shamik picture Shamik · Jul 19, 2012 · Viewed 43.8k times · Source

I'm facing "Circular Placeholder reference" exception while trying to run an executable jar file. Here's the detailed exception.


org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'postProcessProperties' defined in class path resource [applicationContext.xml]: Circular placeholder reference 'processor.core.poolsize' in property definitions
     [echo]     at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:287)
     [echo]     at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
     [echo]     at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:663)
     [echo]     at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:638)
     [echo]     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407)
     [echo]     at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
     [echo]     at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
     [echo]     at com.autodesk.postprocess.engine.PostProcessEngine.start(PostProcessEngine.java:39)
     [echo]     at com.autodesk.postprocess.engine.PostProcessEngine.main(PostProcessEngine.java:29)

This is a spring application which uses an external property file to read values at startup. Here's the spring definition. This has worked pretty well till now.


<bean id="propertyConfig"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_NEVER" />
        <property name="ignoreResourceNotFound" value="true" />
        <property name="locations">
            <list>
                <value>classpath:/postprocess.properties</value>
            </list>
        </property>
        <property name="properties">
            <props>
                <prop key="processor.core.poolsize">${processor.core.poolsize}</prop>
                <prop key="processor.max.poolsize">${processor.max.poolsize}</prop>
            </props>
        </property>
    </bean>

    <bean id="postProcessProperties"
        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="properties">
            <props>
                <prop key="processor.core.poolsize">${processor.core.poolsize}</prop>
                <prop key="processor.max.poolsize">${processor.max.poolsize}</prop>
                <prop key="processor.polling.delay">${processor.polling.delay}</prop>
                <prop key="processor.polling.period">${processor.polling.period}</prop>
        </property>
    </bean>

I'm using shade plugin to generate the jar file. Here's a snippet


<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.7.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.test.postprocess.engine.PostProcessEngine</mainClass>
                                </transformer>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.handlers</resource>
                                </transformer>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.schemas</resource>
                                </transformer>
                            </transformers>
                            <filters>
                                <filter>
                                    <artifact>:</artifact>
                                    <excludes>
                                        <exclude>META-INF/.SF</exclude>
                                        <exclude>META-INF/.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

I'm not sure what's causing this issue, as I've used similar pattern before in other executable jar files.

Any pointer will be appreciated.

Thanks

Answer

Pragmatic picture Pragmatic · Jul 30, 2015

Its probably late to answer this, but adding it for benefit of someone facing similar issue.

I was able to fix it by changing the key names. e.g.

 <prop key="processor.core.poolsize">${processor.core.poolsize}</prop>
 <prop key="processor.max.poolsize">${processor.max.poolsize}</prop>

Was changed to something like

<prop key="processor.core.poolsize">${core.poolsize}</prop>
<prop key="processor.max.poolsize">${max.poolsize}</prop>

property-placeholder key and the key of property value to be filtered cannot be same.