Announcement Announcement Module
Collapse
No announcement yet.
Cannot find WEB-INF/spring.properties error trying to create new ApplicationContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot find WEB-INF/spring.properties error trying to create new ApplicationContext

    I've been stuck on this issue for a while now and feel that I am completely lost, even after posting on other forums and searching. I want to instantiate a Spring-managed bean so am first trying to create a new instance of ApplicationContext and am trying to do so, like below:

    Code:
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext ( "applicationContext.xml" );
    But When this line of code is called in the application I get an error:

    Code:
    java.io.FileNotFoundException: class path resource [WEB-INF/spring.properties] cannot be opened because it does not exist
    I have made sure that spring.properties is in my .classpath file in the root of my application and have also tried having it in /WEB-INF/classes as well as just /WEB-INF. Also, I have tried putting the code below into my applicationContext.xml file and have tried various variations on it, as advised elsewhere, but nothing solves the issue:

    Code:
    <bean id="propertyConfigurer" 
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="spring.properties" />
    </bean>
    I would greatly appreciate if anyone can be patient with my lack of understanding on this issue and point me in the right direction. Thanks

  • #2
    Why do you have a WEB-INF directory in the first place? Is this because you have a war file web application here. Which means you want to create an ApplicationContext via adding the ContextLoaderListener to your web.xml file and have the ApplicationContext created and bootstrapped for you when you deploy your war file.

    In a war file the root and the WEB-INF directories aren't in your classpath. However, the classpath is set to /WEB-INF/classes and WEB-INF/lib so if you really want to still programmatically create a ClassPathXmlApplicationContext, you can put your files in the /WEB-INF/classes directory and now it is at the root of your classpath.

    Mark

    Comment

    Working...
    X