调度程序在Spring Boot中未运行。

12 浏览
0 Comments

调度程序在Spring Boot中未运行。

我创建了一个Spring Boot应用程序。我已经配置了包含调度器方法startService()的类。

以下是我的代码:

服务类:

package com.mk.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.mk.envers.model.BossExtChange;
import com.mk.envers.model.BossExtChangeRepository;
@Component
public class EnverseDemoService {
    @Autowired
    BossExtChangeRepository bossExtChangeRepository;
    @Scheduled(fixedRate = 30000)
    public void startService() {
        System.out.println("调用startService()");
        BossExtChange bossExtChange = bossExtChangeRepository.findById(5256868L);
        System.out.println("bossExtChange.getDescription()--->"+bossExtChange.getDescription());
        System.out.println("结束startService()");
    }
}

主类:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
@PropertySource("classpath:application.properties")
public class EnverseDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(EnverseDemoApplication.class, args);
    }
}

我将该类注释为@Component,方法注释为@Scheduled(fixedRate = 30000),以便作为调度程序运行。但是,在运行Spring Boot应用程序时,调度程序没有触发。控制台显示如下消息:

2016-02-03 10:56:47.708  INFO 10136 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : 注册要在启动时公开的JMX bean
2016-02-03 10:56:47.721  INFO 10136 --- [           main] com.mk.envers.EnverseDemoApplication     : 在3.231秒内启动EnverseDemoApplication(JVM运行时间为3.623秒)
2016-02-03 10:56:47.721  INFO 10136 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : 正在关闭org.springframework.context.annotation.AnnotationConfigApplicationContext @ 49e202ad:启动日期[星期三,2月03日10:56:44 IST 2016];上下文层次结构的根
2016-02-03 10:56:47.721  INFO 10136 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : 注销JMX公开的bean
2016-02-03 10:56:47.736  INFO 10136 --- [       Thread-2] j.LocalContainerEntityManagerFactoryBean : 为持久化单元“默认”关闭JPA EntityManagerFactory

请问有人可以帮我吗?

0