由于缺少EmbeddedServletContainerFactory,无法启动EmbeddedWebApplicationContext

时间:2015-01-19 00:33:00

标签: spring spring-boot scheduling

我需要编写一个具有REST服务和调度程序的spring boot应用程序。

My Maven POM具有以下依赖关系

spring-boot-starter
spring-boot-starter-test
spring-boot-starter-web
spring-boot-starter-data-jpa

我的主要应用程序与REST完美配合。但是当它添加一个调度程序时它给了我

Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

@Configuration    
@EnableAutoConfiguration  
@ComponentScan   

public class ServiceApplication extends SpringBootServletInitializer {   

    public static void main(final String[] args) {
        SpringApplication.run(ServiceApplication.class, args);
        SpringApplication.run(MyTasks.class);
    }

    @Override
    protected final SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
        return application.sources(ServiceApplication.class);
    }
}

这是我的Scheduler类

@EnableScheduling
public class MyTasks {

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRate = 50)
    public void reportCurrentTime() {
        System.out.println("MyTasks : The time is now " + dateFormat.format(new Date()));
    }
}

我们可以从同一个春季启动应用程序执行REST和调度。我已单独测试,但两者都在工作

0 个答案:

没有答案
相关问题