【问题标题】:Spring ,could not resolve place holder,can someone explain me春天,无法解决占位符,有人可以解释一下吗
【发布时间】:2013-10-24 14:39:40
【问题描述】:

我以前从未使用过spring,甚至没有学过它,在我的工作场所中,当我在tomcat中运行应用程序时,我收到以下错误。我不明白,这是什么意思。占位符在${}中的值。 .应用程序中没有错误,我在日志文件中收到此错误

org.springframework.beans.factory.BeanDefinitionStoreException:在类路径资源 [SpringIntegration.xml] 中定义的名称为“”的 bean 定义无效:无法解析占位符“”

日志文件:

Oct 25, 2013 10:40:23 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Oct 25, 2013 10:40:26 AM org.apache.catalina.core.ApplicationContext log
INFO: StartupServlet: Executing StartupServlet.init()
Oct 25, 2013 10:40:26 AM org.apache.catalina.core.ApplicationContext log
INFO: StartupServlet: StartupServlet.init() successfully executed
Oct 25, 2013 10:40:29 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Oct 25, 2013 10:40:30 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 'CWSJMSClient' defined in class path resource [SpringIntegration.xml]: Could not resolve placeholder 'VHF.CWS.Hybrid.Contract.RequestQueue'
    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)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:638)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:968)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1646)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

2013 年 10 月 25 日上午 10:40:30 org.apache.catalina.core.ApplicationContext 日志 信息:关闭 Spring 根 WebApplicationContext

【问题讨论】:

  • 请提供完整的堆栈跟踪。你的问题似乎很模糊

标签: spring tomcat


【解决方案1】:

听起来您正在尝试在 spring 配置中使用外部属性,但没有正确配置 PropertyPlaceholderConfigurer bean。参考本教程:http://www.mkyong.com/spring/spring-propertyplaceholderconfigurer-example/

在那里,您将找到有关如何声明包含变量配置的属性文件的详细说明,例如:

database.username=myusername
database.password=mypassword
...

然后,您使用 PropertyPlaceholderConfigurer 引用该文件:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>database.properties</value>
    </property>
</bean>

【讨论】:

  • 请注意,您也可以使用上下文命名空间中提供的简写。
  • +1 但在使用命名空间之前,请尝试了解这些命名空间在幕后为您做了什么。 (听起来 OP 对 spring 来说很新。)
  • 啊,好点@kungfuters。当您需要做一些开箱即用未提供的事情时,学习基础设施组件的工作方式会派上用场。 . Spring 提供的所有魔力都建立在几个简单的核心组件之上。
【解决方案2】:

将以下行放入属性文件中

VHF.CWS.Hybrid.Contract.RequestQueue=jms://localhost:636

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    • 2016-12-12
    • 2020-03-06
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    相关资源
    最近更新 更多