Testing with Spring and Maven: applicationContext

前端 未结 9 1553
-上瘾入骨i
-上瘾入骨i 2020-12-13 04:04

Seems that question old as world, but I still can\'t find out the solution..

I\'m trying to run simple test:

@RunWith(SpringJUnit4ClassRunner.class)
         


        
9条回答
  •  粉色の甜心
    2020-12-13 05:01

    My test context file is under src\test\resources\spring folder. I managed to load the context with

    @ContextConfiguration(locations={"classpath:**/test-context.xml"})
    

    But reference (in test-context.xml) to the application-context.xml which is under src\main\resources\spring folder failed

    I managed to load the application-context by creating a ClassPathXmlApplicationContext in the test class with

    ClassPathXmlApplicationContext appContext=new ClassPathXmlApplicationContext(new String[]{"classpath:spring/application-context.xml","classpath:spring/model-context.xml"});
    

    Let me know if this helps or might create any other issues.

提交回复
热议问题