无法解析字符串值中的占位符
Posted
技术标签:
【中文标题】无法解析字符串值中的占位符【英文标题】:Could not resolve placeholder in string value 【发布时间】:2017-07-23 14:03:18 【问题描述】:我正在尝试使用 .properties 文件中的属性,但它不起作用。 我收到此错误:
2017-03-03 11:33:22,893 [localhost-startStop-1] [] ERROR org.springframework.web.context.ContextLoader Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException:
Invalid bean definition with name 'sessionFactoryInit'
defined in URL [jar:file:/C:/dev/Escale/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/hx_u4WebServices/WEB-INF/lib/hx_u4Persistence.jar!/META-INF/applicationContext-hibernate-init.xml]:
Could not resolve placeholder 'ipon.hibernate.show_sql' in string value "$ipon.hibernate.show_sql"
你能帮帮我吗?
applicationContext-hibernate-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="sessionFactoryInit" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" abstract="true">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop
key="hibernate.dialect">fr.laposte.courrier.escale.ipon.persistence.dialect.SpecificOracleDialect</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
<prop key="hibernate.show_sql">$ipon.hibernate.show_sql</prop>
<prop key="hibernate.max_fetch_depth">$ipon.hibernate.max_fetch_depth</prop>
<prop key="hibernate.jdbc.fetch_size">$ipon.hibernate.jdbc.fetch_size</prop>
<prop key="hibernate.jdbc.batch_size">$ipon.hibernate.jdbc.batch_size</prop>
<prop key="hibernate.jdbc.use_get_generated_keys">true</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<prop key="hibernate.generate_statistics">$ipon.hibernate.generate_statistics</prop>
</props>
</property>
C:\dev\Escale\u4\Sources\livraison\conf\IPON\config\ipon.properties
ipon.hibernate.show_sql = false
ipon.hibernate.max_fetch_depth = 3
ipon.hibernate.jdbc.fetch_size = 500
ipon.hibernate.jdbc.batch_size = 40
ipon.hibernate.generate_statistics = false
ipon.c3p0.acquireIncrement = 2
ipon.c3p0.initialPoolSize = 60
ipon.c3p0.maxPoolSize = 200
ipon.c3p0.minPoolSize = 40
ipon.c3p0.maxIdleTime = 300
ipon.c3p0.idleConnectionTestPeriod = 20
ipon.c3p0.maxStatements = 50
ipon.rechercheClient.limitation = 60
ipon.rechercheCommande.limitation = 60
# en secondes
ipon.session.timeout = 7200
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
<display-name>iponServices</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>iponServices.root</param-value>
</context-param>
<context-param>
<param-name>logbackConfigLocation</param-name>
<param-value>file:$IPONN/config/log.xml</param-value>
</context-param>
tomcat 7 (eclipse) 中的虚拟机参数 Vm argument Tomcat 7
-DIPONN="C:/dev/Escale/u4/Sources/livraison/conf/IPON"
提前感谢您的帮助。
【问题讨论】:
【参考方案1】:我认为您在上下文中缺少属性占位符 bean:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:$IPONN/config/ipon.properties</value>
</property>
【讨论】:
感谢您的回复。 你可以在你的applicationContext-hibernate-config.xml中添加它以上是关于无法解析字符串值中的占位符的主要内容,如果未能解决你的问题,请参考以下文章
无法解析值“$auth0.audience”中的占位符“auth0.audience”
无法使用 Spring Boot 解析 JavaFX 应用程序的占位符