0

我有一个非常简单的@SpringBootTest

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {...})
public class MyApplicationTest {

    @Test
    public void anyTest() { ... }
}

在我们在文件中添加@EnableSchedulerLock(来自Shedlock)之前,它按预期工作MyApplication.java

因为,我们遇到了这个问题:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: No ServletContext set
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)
    ... 46 common frames omitted
Caused by: java.lang.IllegalStateException: No ServletContext set
    at org.springframework.util.Assert.state(Assert.java:73)
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:483)

当 Spring 尝试实例化它时,就会发生这种情况resourceHandlerMapping

@Bean
public HandlerMapping resourceHandlerMapping() {
    Assert.state(this.applicationContext != null, "No ApplicationContext set");
    Assert.state(this.servletContext != null, "No ServletContext set");
    ...

这就像在调用(from )@Bean之前创建的。setServletContextWebMvcConfigurationSupport

4

1 回答 1

0

正如 Lukas 所说,这个错误已在最新版本的 Shedlock 中得到修复。

升级 Shedlock 的版本2.2.0解决2.5.0问题。

于 2019-05-29T06:23:25.210 回答