使用XML定义的上下文运行Spring引导Junit测试

时间:2016-05-20 11:13:06

标签: spring junit spring-boot

我有一个带有@ImportResource的app-context.xml的Spring启动应用程序,如下所示:

@SpringBootApplication
@ImportResource("META-INF/app-context.xml")
public class BootProjApplication {

    public static void main(String[] args) {
        // creates an app context
        SpringApplication.run(BootProjApplication.class, args);
    }


}

但是当我启动以下JUnit测试时:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = BootProjApplication.class)
@WebAppConfiguration
@Transactional
public class UserServiceTest {

    @Autowired
    UserService userService;


    @Test
    public void contextLoads() {

    }

    @Test
    public void testFindById() {

    ...
    }

我有这个错误:

java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate...

Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/META-INF/app-context.xml] at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE] at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
... 44 common frames omitted

0 个答案:

没有答案
相关问题