Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Circular placeholder reference while running an executable jar

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

like image 665
Shamik Avatar asked Jul 18 '12 22:07

Shamik


3 Answers

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.

like image 77
Pragmatic Avatar answered Nov 15 '22 01:11

Pragmatic


Circular placeholder reference XXXX in property definitions

Above kind of exception will be thrown by the spring-framework when your property key name and value variable name are exactly the same.

Make sure your property should not look like key={$key}. Keeping different name for key and value will fix this issue.

like image 13
Abhishek Avatar answered Nov 15 '22 02:11

Abhishek


I was having the same issue when trying to run a spring integration test using SpringJUnit4ClassRunner. I was unsure of how to get my properties file loaded and after a few mis-steps, I found the @TestPropertySource annotation that allowed me to define the properties file(s) needed.

I had tried @PropertySource before that, and it does not work when you are running a spring integration test like this.

Hopefully this helps someone else.

like image 2
Becky reamy Avatar answered Nov 15 '22 00:11

Becky reamy