Announcement Announcement Module
Collapse
No announcement yet.
class path resource [myConfigFile.xml] cannot be opened because it doesn't exit Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • class path resource [myConfigFile.xml] cannot be opened because it doesn't exit

    I am trying to unit test my job. I have Maven as my build tool. My resource files for test is under src/test/resources, but i get the following error when I try to run just my testSimpleProperties method.

    Code:
    @ContextConfiguration(locations = {"classpath:applicationContext.xml"})
    @RunWith(LmTestJUnit4ClassRunner.class)
    public class TestIrFastighetJob {
    
        @Autowired
        private JobLauncher jobLauncher;
    
        @Autowired
        private JobRegistry jobRegistry;
    
        /**
         * @throws Exception
         */
        @Test
        public void testSimpleProperties() throws Exception {
            assertNotNull(this.jobLauncher);
            assertNotNull(this.jobRegistry);
        }
    
    
        @Test
        public void testRead() {
            fail("Not yet implemented");
        }
    
    }
    and the error messages is

    HTML Code:
    2011-03-25 10:30:38,725 [main] ERROR Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@bfea1d] to prepare test instance [se.lantmateriet.milins.migration.irfastighet.steps.createExchangeObjects.domain.TestIrFastighetJob@1a33d48] at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:324)
    java.lang.IllegalStateException: Failed to load ApplicationContext
    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
    	at se.lantmateriet.test.junit.LmTestJUnit4ClassRunner.createTest(LmTestJUnit4ClassRunner.java:23)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
    	at se.lantmateriet.test.junit.LmTestJUnit4ClassRunner.runChild(LmTestJUnit4ClassRunner.java:10)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
    	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
    	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:146)
    	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
    	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.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
    	at $Proxy0.invoke(Unknown Source)
    	at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145)
    	at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87)
    	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
    Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
    	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:81)
    	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
    	at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
    	... 31 more
    Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
    	at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
    	... 40 more

  • #2
    ensure the file is on the classpath and there's no typo in the name. Try also to add a / before the name of the file (e.g. classpath:/applicationContext.xml).

    Comment


    • #3
      Originally posted by arno View Post
      ensure the file is on the classpath and there's no typo in the name. Try also to add a / before the name of the file (e.g. classpath:/applicationContext.xml).
      Thanks Arno for the answer!
      I have similar project which I run my unit test like this one. I do not know what the problem is. Maven does not build the test-classes folder under target (my output folder for test classes and resources)... very strange....
      The problem is not figured out yet

      Comment


      • #4
        The problem is solved now! Very strange reason, The reason was test does not like the name of my config file name. I used another name as my master config file.

        If any one know why applicationContext.xml is not a good name, please let me know I will be thankful to know the reason.

        /Sheri

        Comment

        Working...
        X