gpt4 book ai didi

java - 运行可执行 jar 时的 Spring 循环占位符引用

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:52:58 25 4
gpt4 key购买 nike

我在尝试运行可执行 jar 文件时遇到“循环占位符引用”异常。这是详细的异常。


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)

这是一个 spring 应用程序,它使用外部属性文件在启动时读取值。这是 Spring 的定义。到目前为止,这种方法运行良好。


<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>

我正在使用 shade 插件生成 jar 文件。这是一个片段


<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><em>:</em></artifact>
<excludes>
<exclude>META-INF/<em>.SF</exclude>
<exclude>META-INF/</em>.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>

我不确定是什么导致了这个问题,因为我之前在其他可执行 jar 文件中使用过类似的模式。

任何指针将不胜感激。

谢谢

最佳答案

回答这个问题可能已经晚了,但添加它是为了让面临类似问题的人受益。

我能够通过更改键名来修复它。例如

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

被改成了类似的东西

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

property-placeholder key和要过滤的property value的key不能相同。

关于java - 运行可执行 jar 时的 Spring 循环占位符引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11551083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com