我有一个组件类
@Component
public class Scheduler
{
@Scheduled(fixedRate = 5000 )
public void test()
{
System.out.println("Hi");
}
}但是"Hi“并不是每5秒打印一次。为什么?
我的Confuration类是
@ComponentScan( excludeFilters = { @ComponentScan.Filter( type = FilterType.ASSIGNABLE_TYPE ) } )
@EnableScheduling
@SpringBootApplication
public class Application
{
public static void main( final String[] args )
{
LOG.debug("Booting Spring Application ...... ");
SpringApplication.run(Application.class, args);
}
}发布于 2017-05-22 20:47:38
在您的主应用程序类中添加@EnableScheduling,如果您没有扫描所有包,还会看到使用@ComponentScan扫描了保存排定程序的包。
@EnableScheduling
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan(basePackages = "springboot.service,springboot.dao,springboot.rest,springboot.schedule,springboot.controller")
public class StartUpController {
public static void main(String[] args) throws Exception {
SpringApplication.run(StartUpController.class, args);
}
}发布于 2017-05-22 20:57:41
您的Scheduler类是在应用程序类的同一个包中还是在一个子包中?如果没有,则必须将base-packages属性添加到@ComponentScan注释中,以便找到排定程序组件。
https://stackoverflow.com/questions/44112432
复制相似问题