我有我的配置:
<context:property-placeholder location="classpath:idm.properties" />
<bean id="idmPropertyHolder" class="fi.utu.resurssitilaus.idm.IdmPropertyHolder">
<property name="url" value="${idm.url}" />
<property name="user" value="${idm.user}" />
<property name="password" value="${idm.password}" />
<property name="proxyHost" value="${http.proxyHost}" />
<property name="proxyPort" value="${http.proxyPort}" />
</bean>
我收到错误
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 'idmPropertyHolder' defined in ServletContext resource [/WEB-INF/idm-config.xml]: Could not resolve placeholder 'idm.url'
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:272)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:640)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:615)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:405)
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:3934)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:514)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1288)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1473)
at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:824)
at org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:350)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:196)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
24.1.2011 9:19:05 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
24.1.2011 9:19:05 org.apache.catalina.core.ApplicationContext log
INFO: Shutting down log4j
我知道这可能是缺少属性文件,但我在我的classpath中恰到好处。缺什么?
我的web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/base-config.xml
/WEB-INF/idm-config.xml
/WEB-INF/ldap-config.xml
/WEB-INF/sec-config.xml
</param-value>
</context-param>
<!-- Reads request input using UTF-8 encoding -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<!-- Handles all requests into the application -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/app-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>tiles</servlet-name>
<servlet-class>org.apache.tiles.web.startup.TilesServlet</servlet-class>
<init-param>
<param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
</param-name>
<param-value>
/WEB-INF/tiles-config.xml
</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>
答案 0 :(得分:100)
您的申请中可能有多个org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
。尝试在超类的setLocations
方法上设置断点,看看它是否在应用程序启动时被调用了多次。如果有多个org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
,您可能需要查看配置ignoreUnresolvablePlaceholders
属性,以便您的应用程序能够干净地启动。
答案 1 :(得分:15)
您的媒体资源文件位置为classpath:idm.properties
这很不寻常,这意味着idm.properties
必须位于WEB-INF/classes
的顶层或WEB-INF/lib
内的其中一个广告的顶层。通常,最好使用专用文件夹作为属性,或者使它们靠近使用它们的上下文文件。
所以我的建议是这样的:您的属性文件是否可能在您的上下文文件旁边?如果是这样,它不在类路径上(请参阅此问题:Is WEB-INF in the CLASSPATH?)。
classpath:
前缀映射到ClassPathResource
,但您可能需要ServletContextResource
,并且您将使用不带前缀的语法从WebApplicationContext
获取该前缀:< / p>
<context:property-placeholder location="idm.properties" />
<强>参考:强>
ResourceLoader
ApplicationContext
类型如何处理没有前缀的资源)PropertyPlaceholderConfigurer
mechanism <context:property-placeholder>
机制)答案 2 :(得分:11)
找不到属性文件肯定不是问题,因为在这种情况下会抛出另一个异常。
确保您idm.url
中的密钥idm.properties
确实有值。
答案 3 :(得分:3)
我仍然认为它与弹簧未找到的道具文件有关。通过将params作为jvm params进行快速测试。即 -Didm.url = ....
答案 4 :(得分:2)
确保您的属性文件存在于classpath目录中,但不存在于classpath目录的子文件夹中。如果它存在于子文件夹中,则写入如下classpath:subfolder / idm.properties
答案 5 :(得分:0)
必须在gradle.build文件中添加以下属性
processResources {
filesMatching("**/*.properties") {
expand project.properties
}
}
此外,如果使用Intellij,则必须重新导入项目。
答案 6 :(得分:-7)
确保在属性文件中设置'idm.url'并加载属性文件