Could not open ServletContext resource

后端 未结 8 833
情歌与酒
情歌与酒 2020-12-05 02:16

This is quite similar question to one older but the solution did not work for me.

I have a WAR package.

In web.xml



        
相关标签:
8条回答
  • 2020-12-05 02:46

    Put the things like /src/main/resources/foo/bar.properties and then reference them as classpath:/foo/bar.properties.

    0 讨论(0)
  • 2020-12-05 02:49

    Try to use classpath*: prefix instead.

    http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/resources.html#resources-classpath-wildcards

    Also please try to deploy exploded war, to ensure that all files are there.

    0 讨论(0)
  • 2020-12-05 02:52

    Mark sure propertie file is in "/WEB-INF/classes" try to use

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>/WEB-INF/classes/social.properties</value>
        </property>
    </bean>
    
    0 讨论(0)
  • 2020-12-05 02:56

    I had the same error.

    My filename was jpaContext.xml and it was placed in src/main/resources. I specified param value="classpath:/jpaContext.xml".

    Finally I renamed the file to applicationContext.xml and moved it to the WEB-INF directory and changed param value to /WEB-INF/applicationContext.xml, then it worked!

    0 讨论(0)
  • 2020-12-05 02:59

    Are you having Tomcat unpack the WAR file? It seems that the files cannot be found on the classpath when a WAR file is loaded and it is not being unpacked.

    0 讨论(0)
  • 2020-12-05 03:04

    Do not use classpath. This may cause problems with different ClassLoaders (container vs. application). WEB-INF is always the better choice.

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-config.xml</param-value>
    </context-param>
    

    and

    <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
         <property name="location">
             <value>/WEB-INF/social.properties</value>
         </property>
    </bean>
    
    0 讨论(0)
提交回复
热议问题