我不确定说出这个问题的最好方法,因为我不知道为什么会这样。
当我在没有spring-integration-core jar的情况下启动Spring Boot应用程序时,我的应用程序启动正常。第二个我将spring-boot-starter-integration或任何spring-integration-core库添加到我的Maven pom文件中,我的DelegatingWebMvcConfiguration
类上的servlet上下文始终为null,我收到以下错误:
java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
在做了一些调试之后,我看到在DelegatingWebMvcConfiguration
为我的应用程序设置servlet上下文之前初始化EmbeddedWebApplicationContext
类,这对于为什么我的DelegatingWebMvcConfiguration
的servlet上下文为空是有道理的为在postProcessBeforeInitialization
中使用ServletContextAwareProcessor
初始化的所有其他类设置。简单地删除Spring Integration依赖项就可以解决问题,但是我想在我的Boot应用程序中使用Spring Integration。
我的问题是在DelegatingWebMvcConfiguration
调用EmbeddedWebApplicationContext
方法之前导致prepareEmbeddedWebApplicationContext
的原因是什么。
使用Spring Boot 1.1.8.RELEASE的Spring依赖项: org.springframework.boot 弹簧引导启动的Web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>0.16.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-core</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>4.1.2.RELEASE</version>
</dependency>
我的根配置文件:
@Configuration
@EnableAutoConfiguration
@EnableAsync
@EnableEntityLinks
@EnableSpringDataWebSupport
@ComponentScan
@PropertySource(value = "file:../application.properties",
ignoreResourceNotFound = true)
public class ApplicationInitializer extends SpringBootServletInitializer
implements EmbeddedServletContainerCustomizer {
public static void main(String[] args) throws Exception {
SpringApplication.run(ApplicationInitializer.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application){
return application.sources(ApplicationInitializer.class);
}
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
container.setContextPath(APPLICATION_ROOT_PATH);
}
// Global beans defined here
}
更新:在尝试了很多不同的事情后,我发现在禁用我的SchedulingConfigurer后,我的应用程序现在启动了。这是我的SchedulingConfigurer
@Configuration
@EnableScheduling
@EnableConfigurationProperties(SchedulingProperties.class)
public class SchedulingConfig implements SchedulingConfigurer {
//Inject Runnables and properties
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskScheduler());
// call taskRegistrar.addFixedRateTask with runnable and property rate value
}
@Bean(destroyMethod = "shutdown")
public Executor taskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
return taskScheduler;
}
}