Announcement Announcement Module
Collapse
No announcement yet.
classpath resources and context testing Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • classpath resources and context testing

    Hi!

    I've recently started to use a custom subclass of AbstractDependencyInjectionSpringContextTests
    which should be able to load configLocations as classpaths.

    However, from inside Eclipse, I keep getting messages such as

    org.springframework.beans.factory.BeanDefinitionSt oreException: IOException parsing XML document from class path resource [ /WebContent/WEB-INF/shady-servlet.xml]; nested exception is java.io.FileNotFoundException: class path resource [ /WebContent/WEB-INF/shady-servlet.xml] cannot be opened because it does not exist
    java.io.FileNotFoundException: class path resource [ /WebContent/WEB-INF/shady-servlet.xml] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getI nputStream(ClassPathResource.java:160)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:160)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:125)
    at org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:141)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:113)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:81)
    at org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:89)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:268)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:81)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:66)
    at org.springframework.test.AbstractSpringContextTest s.loadContextLocations(AbstractSpringContextTests. java:121)
    at org.springframework.test.AbstractDependencyInjecti onSpringContextTests.loadContextLocations(Abstract DependencyInjectionSpringContextTests.java:161)
    at org.springframework.test.AbstractSpringContextTest s.getContext(AbstractSpringContextTests.java:101)
    at org.springframework.test.AbstractDependencyInjecti onSpringContextTests.setUp(AbstractDependencyInjec tionSpringContextTests.java:129)
    at junit.framework.TestCase.runBare(TestCase.java:125 )
    at junit.framework.TestResult$1.protect(TestResult.ja va:106)
    at junit.framework.TestResult.runProtected(TestResult .java:124)
    at junit.framework.TestResult.run(TestResult.java:109 )
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:421)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:305)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:186)

    Well, it does exist......

    Quote from the docs for AbstractDependencyInjectionSpringContextTests

    WARNING: When doing integration tests from within Eclipse, only use classpath resource URLs. Else, you may see misleading failures when changing context locations.

    Well, I am doing my best.
    Here's my test.properties file:

    ctx.path.1=classpath:/WebContent/WEB-INF/applicationContext-Hibernate.xml
    ctx.path.2=classpath:/WebContent/WEB-INF/burlap-servlet.xml
    ctx.path.3=classpath:/WebContent/WEB-INF/shady-businesslogic.xml
    ctx.path.4=classpath:/WebContent/WEB-INF/shady-mail.xml
    ctx.path.5=classpath: /WebContent/WEB-INF/shady-servlet.xml

    Anybody recognize this?
    Verrry annoying....

    Thanks!

  • #2
    I think that you need to set the "working directory" in your Eclipse run configuration to match the directory that contains WEB-INF/...
    Hope this helps.

    Comment


    • #3
      Yes, that helped! A whole new bunch of new Exceptions, but I've gotten a fair bit on the road.
      Thanks!

      Comment


      • #4
        Need to insure the proper class loader is set

        When you initialize a spring context in an eclipse plugin you need to make sure you are using the correct class loader.

        You should use the following code around the initialization

        Thread cur = Thread.currentThread();
        ClassLoader save = cur.getContextClassLoader();
        cur.setContextClassLoader(plugin.getClass().getCla ssLoader());
        try
        {
        ... Initialize the spring contexts.
        }
        finally
        {
        cur.setContextClassLoader(save);
        }

        This code will insure that you can see the context.xml files.

        Comment

        Working...
        X