Spring中报"Could not resolve placeholder"的解决方案

除去properites文件路径错误、拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderConfigurer或者多个<context:property-placeholder>的原因。

 

  比如我有一个dao.xml读取dbConnect.properties,还有一个dfs.xml读取dfsManager.properties,然后web.xml统一load这两个xml文件

Xml代码  收藏代码
  1. <context-param>  
  2.         <param-name>contextConfigLocation</param-name>  
  3.         <param-value>  
  4.                 WEB-INF/config/spring/dao.xml,   
  5.                 WEB-INF/config/spring/dfs.xml  
  6.         </param-value>  
  7. </context-param>  

如果这两个xml文件中分别有

Xml代码  收藏代码
  1. <!-- dao.xml -->  
  2. <context:property-placeholder location="WEB-INF/config/db/dbConnect.properties" />  
  3.   
  4. <!-- dfs.xml -->  
  5. <context:property-placeholder location="WEB-INF/config/dfs/dfsManager.properties" />  

那么,一定会出"Could not resolve placeholder"。

 

  一定要记住,不管是在一个Spring文件还是在多个Spring文件被统一load的情况下,直接写

Xml代码  收藏代码
  1. <context:property-placeholder location="" />  
  2. <context:property-placeholder location="" />   

是不允许的。

 

解决方案:

  (1) 在Spring 3.0中,可以写:

Xml代码  收藏代码
  1. <context:property-placeholder location="xxx.properties" ignore-unresolvable="true"  
  2. />  
  3. <context:property-placeholder location="yyy.properties" ignore-unresolvable="true"  
  4. />  

注意两个都要加上ignore-unresolvable="true",一个加另一个不加也是不行的

 

  (2) 在Spring 2.5中,<context:property-placeholder>没有ignore-unresolvable属性,此时可以改用PropertyPlaceholderConfigurer。其实<context:property-placeholder location="xxx.properties" ignore-unresolvable="true" />与下面的配置是等价的

Java代码  收藏代码
  1. <bean id="随便" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  2.     <property name="location" value="xxx.properties" />  
  3.     <property name="ignoreUnresolvablePlaceholders" value="true" />   
  4. </bean>  

  正因为如此,写多个PropertyPlaceholderConfigurer不加ignoreUnresolvablePlaceholders属性也是一样会出"Could not resolve placeholder"。

 

  虽然两者是的等价的,但估计大家还是喜欢写<context:property-placeholder>多一些,毕竟简单一些嘛。所以如果是Spring 3.0,直接用解决方案(1)再简单不过了;如果是Spring 2.5,需要费点力气改写成PropertyPlaceholderConfigurer


https://blog.csdn.net/linwei_1029/article/details/6873764

阅读更多

Could not resolve placeholder

03-05

2012-03-05 12:11:13,836] main org.springframework.web.context.ContextLoader ERROR - Context initialization failedrnorg.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name '_formLoginFilter' defined in null: Could not resolve placeholder 'ql.security.cas.server.loginUrl'rn at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:268)rn at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)rn at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:553)rn at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:527)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:362)rn at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3795)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4252)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:980)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:943)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1203)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:319)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:448)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:552)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)rn[2012-03-05 12:11:13,840] main org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/anyangwrm] ERROR - Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

Could not resolve placeholder 'hibernate.driverClassName'

12-16

将Tomcat下的SSH架构的项目移植到weblogic下,tomcat下是可以运行的rnrn在weblogic下部署项目rnrn部署成功,登陆页面点击登录报错No bean named 'sessionFactory' is definedrnrn然后我在weblogic.xml下加入rn rn true rn rnrn再在weblogic下部署,部署失败,并报错rnweblogic.application.ModuleException: :org.springframework.beans.factory.BeanDefinitionStoreException:Invalid bean definition with name 'dataSource' defined in file [D:\SDK\Workspace\Workspace fo MyEclipse\PersonnelPro\WebRoot\WEB-INF\classes\applicationContext-common.xml]: Could not resolve placeholder 'hibernate.driverClassName'rnrn我的applicationContext-common.xml文件rnrnrnrn rn rn rn rn classpath:hibernate.propertiesrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrn rn rnrn rn rn rn truern updatern rn org.hibernate.dialect.OracleDialectrn rn rn rn rn rn rn rn com/personnel/model/Message.hbm.xmlrn com/personnel/model/Organization.hbm.xmlrn com/personnel/model/User.hbm.xmlrn rn rn rnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn mgr rn rn rn rn rn rn rn rn transactionInterceptor rn rn rn rn rn rnrnrnrn我的web.xml文件rnrnrnrnrnrn rn rncontextConfigLocation rn classpath:applicationContext-*.xmlrnrn rn rn org.springframework.web.context.ContextLoaderListener rn rn rnrn rn rn rn encodingFilterrn org.springframework.web.filter.CharacterEncodingFilterrn rn encodingrn gbkrn rn rn rn pathfilterrn com.personnel.filter.FilterServletrn rn rn pathfilterrn /*rn rn rn rn rn struts2rn org.apache.struts2.dispatcher.FilterDispatcherrn rn rn rn hibernateFilterrn org.springframework.orm.hibernate3.support.OpenSessionInViewFilterrn rn rn hibernateFilterrn *.actionrn rn rn encodingFilterrn *.actionrn rn rn encodingFilterrn *.jsprn rn rn struts2rn *.actionrn rn rn rn rn ConnectorServletrn rn net.fckeditor.connector.ConnectorServletrn rn 1rn rnrn rn ConnectorServletrn /fckeditor/editor/filemanager/connectors/*rn rnrn rnrn login.jsprnrnrnrnrn

Spring错误:Could not resolve placeholder 'jdbc.driver'

07-27

使用spring-framework-3.0.3,配置文件如下:rnapplicationContext.xmlrn[code=XML]rnrn]>rnrn rn rn /WEB-INF/config/jdbc.propertiesrn rn rn rn rn rn rn rn rn[/code]rnrnjdbc.properties文件在/WEB-INF/config目录下rn[code=XML]jdbc.driver=oracle.jdbc.OracleDriverrnjdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orclrnjdbc.user=scottrnjdbc.password=tiger[/code]rnrn当启动tomcat时,产生如下错误rn[code=XML]严重: Context initialization failedrnorg.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dataSource' defined in ServletContext resource [/WEB-INF/config/applicationContext.xml]: Could not resolve placeholder 'jdbc.driver'rn at org.springframework.beans.factory.config.PropertyPlaceholderConfigurernr.processProperties(PropertyPlaceholderConfigurer.java:272)rn at org.springframework.beans.factory.config.PropertyResourceConfigurer.prnostProcessBeanFactory(PropertyResourceConfigurer.java:75)rn at org.springframework.context.support.AbstractApplicationContext.invokernBeanFactoryPostProcessors(AbstractApplicationContext.java:663)rn at org.springframework.context.support.AbstractApplicationContext.invokernBeanFactoryPostProcessors(AbstractApplicationContext.java:638)rn at org.springframework.context.support.AbstractApplicationContext.refresrnh(AbstractApplicationContext.java:407)rn at org.springframework.web.context.ContextLoader.createWebApplicationConrntext(ContextLoader.java:276)rn at org.springframework.web.context.ContextLoader.initWebApplicationConternxt(ContextLoader.java:197)rn at org.springframework.web.context.ContextLoaderListener.contextInitialirnzed(ContextLoaderListener.java:47)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContexrnt.java:4323)rn at org.apache.catalina.core.StandardContext.startInternal(StandardContexrnt.java:4771)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:138)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBasern.java:785)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:76rn3)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:558)rnrn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.javrna:1124)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.jrnava:1047)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:542rn)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1390)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.javarn:355)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecyclrneSupport.java:119)rn at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBarnse.java:89)rn at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:31rn2)rn at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:29rn2)rn at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.jarnva:998)rn at org.apache.catalina.core.StandardHost.startInternal(StandardHost.javarn:772)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:138)rn at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.jarnva:990)rn at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.rnjava:275)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:138)rn at org.apache.catalina.core.StandardService.startInternal(StandardServicrne.java:424)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:138)rn at org.apache.catalina.core.StandardServer.startInternal(StandardServer.rnjava:648)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:138)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:576)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.rnjava:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesrnsorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)rn2010-7-27 11:18:35 org.apache.catalina.core.StandardContext startInternal[/code]rnrn为什么会产生上面的错误呢?如何修改?rn谢谢!rn

没有更多推荐了,返回首页