Spring引导计划任务自行关闭

时间:2015-10-19 12:49:25

标签: java spring spring-boot

我已经创建了一个Spring引导计划任务,如link中所述。当我运行应用程序时,它只是启动和停止,而我无法看到指南中提到的输出。在日志下面

2015-10-19 17:54:14.366  INFO 4512 --- [lication.main()] o.litmos.workday.batch.app.Application   : Starting Application on RohitNagesh-PC with PID 1118
2015-10-19 17:54:14.418  INFO 4512 --- [lication.main()] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@84cebe: startup date [Mon Oct 19 17:54:14 IST 2015]; root of context hierarchy
2015-10-19 17:54:14.790  INFO 4512 --- [lication.main()] o.s.b.f.xml.XmlBeanDefinitionReader      : Loading XML bean definitions from class path resource [applicationContext.xml]
2015-10-19 17:54:15.088  INFO 4512 --- [lication.main()] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.scheduling.annotation.SchedulingConfiguration' of type [class org.springframework.scheduling.annotation.SchedulingConfiguration$$EnhancerBySpringCGLIB$$3770f0ed] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-10-19 17:54:15.258  INFO 4512 --- [lication.main()] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2015-10-19 17:54:15.279  INFO 4512 --- [lication.main()] o.litmos.workday.batch.app.Application   : Started Application in 1.184 seconds (JVM running for 5.503)
2015-10-19 17:54:15.366  INFO 4512 --- [       Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@84cebe: startup date [Mon Oct 19 17:54:14 IST 2015]; root of context hierarchy
2015-10-19 17:54:15.367  INFO 4512 --- [       Thread-1] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

如何让任务在我停止之前无限运行?

添加我的代码

@SpringBootApplication
@EnableScheduling
@ImportResource("applicationContext.xml")
public class Application {

    public static void main(String[] args) {
        System.out.println("Batch Started");
        SpringApplication.run(Application.class);
    }
}


@Component
public class SampleJob {

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

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

的pom.xml

<dependencies>
    <!-- Spring Batch dependencies -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>1.2.7.RELEASE</version>
    </dependency>
</dependencies>

1 个答案:

答案 0 :(得分:0)

你在applicationContext.xml文件中有什么?在您提供的链接中,没有@ImportResource,因此您似乎在Spring xml上配置错误。 如果你想修复它,我宁愿去这个链接: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html