spring在测试时遇到报错

java.lang.NoSuchMethodError: org.springframework.util.Assert.notNull(Ljava/lang/Object;Ljava/util/function/Supplier;)V

    at org.springframework.test.context.support.ContextLoaderUtils.resolveContextConfigurationAttributes(ContextLoaderUtils.java:240)
    at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:295)
    at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildTestContext(AbstractTestContextBootstrapper.java:108)
    at org.springframework.test.context.TestContextManager.(TestContextManager.java:139)
    at org.springframework.test.context.TestContextManager.(TestContextManager

 

原因:spring扫描的包中包含带有@EnableWebMvc这个注解,所以test无法正常测试。

解决:过滤掉相关类,或者在测试类上加上@WebApplicationContext进行配置

参考: 
[1]https://stackoverflow.com/questions/21516683/java-lang-illegalargumentexception-a-servletcontext-is-required-to-configure-de

你可能感兴趣的:(spring在测试时遇到报错)