0
我已經一個屬性文件 -無法解析性佔位符,當屬性內部有一個佔位符
application.properties(如下內容)
core.microsite=q=MarketId:${marketId}&q=PresaleOff
這裏是我的Spring配置XML -
<bean id="myBean" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="location" value="classpath:/application.properties" />
</bean>
<bean id="MyQueryBuilder" class="com.search.builder.impl.MyQueryBuilder">
<property name="queryTemplateMap">
<map>
<entry key="microsite" value="${core.microsite}" />
</map>
</property>
</bean>
現在在服務器啓動時(tomocat)我得到這個例外 -
ug 29, 2012 11:50:05 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'MyQueryBuilder' defined in URL [jar:file:/C:/apache-tomcat-6.0.35/webapps/my-service/WEB-INF/lib/my-app-1.0.2.RC8-SNAPSHOT.jar!/META-INF/spring/config/app-context.xml]: Could not resolve placeholder 'marketId'
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:287)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:663)
它清楚地失敗,因爲core.microsite酒店內部有一個更佔位$ {} marketId
如何解決這個問題呢?
將「ignoreUnresolvablePlaceholders」設置爲true應該起作用(理論上)。不知道現在該做什麼?
欣賞任何指針!
謝謝。
在applicationContext中使用'$ {core.microsite}'時,是否希望'$ {marketId}'替代例如'q = MarketId:12345&q = PresaleOff',或保留爲'q = MarketId:$ {marketId}&q = PresaleOff'? – yorkw
我希望該值保持不變。那就是 - q = MarketId:$ {marketId}&q = PresaleOff – Rishi
嘗試在屬性文件'core.microsite = q = MarketId:\ $ \ {marketId \}&q = PresaleOff'中使用轉義字符。 – yorkw