小编Moh*_*mar的帖子

调度程序未在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("Calling startService()");
        BossExtChange bossExtChange = bossExtChangeRepository.findById(5256868L);
        System.out.println("bossExtChange.getDescription()--->"+bossExtChange.getDescription());
        System.out.println("Ending startService()");
    }
}
Run Code Online (Sandbox Code Playgroud)

主类:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经注释了类@Component和方法,@Scheduled(fixedRate = 30000)因为它将作为调度程序运行.但是在将应用程序作为Spring Boot运行时,调度程序不会触发.控制台显示以下消息:

2016-02-03 10:56:47.708  INFO …
Run Code Online (Sandbox Code Playgroud)

java scheduler spring-boot

11
推荐指数
5
解决办法
2万
查看次数

标签 统计

java ×1

scheduler ×1

spring-boot ×1