Results 1 to 2 of 2

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

  1. #1
    Join Date
    Mar 2011
    Posts
    1

    Default 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. #2
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •