@SpringBootApplication
@EnableScheduling
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserDao userDao;
@Override
public User findById(Long id) {
return userDao.findOne(id);
}
@Scheduled(fixedDelay=3000)
public void testSchedule(){
System.out.println("Hello World");
}
}
out:
Hello World
2018-08-17 10:42:31.115 INFO 26510 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2018-08-17 10:42:31.120 INFO 26510 --- [ main] c.a.d.spring.boot.demo.DemoApplication : Started DemoApplication in 15.179 seconds (JVM running for 20.952)
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
Hello World
6条答案
按热度按时间drnojrws1#
我看下
2eafrhcq2#
我用 Druid Spring Boot Starter 的 DemoApplication 试了下,没问题呀。
config:
spring.datasource.druid.aop-patterns=com.alibaba.druid.spring.boot.demo.service.*
code:
out:
监控:
mec1mxoz3#
你再排查下,看看是不是 Spring 的什么地方配置有问题。
5ktev3wc4#
不知道是我的配置有问题还是怎么的,无论aop-patterns配置为哪个包,spring @scheduled 定时任务都不能执行。自定义了定时任务的线程池,使用jstack命令输出线程堆栈,没有定时任务的线程。换了连接池hikaricp就行了。看了spring schedule部分源码,ScheduledAnnotationBeanPostProcessor.finishRegistration()没有执行。
blpfk2vs5#
对
mmvthczy6#
https://github.com/alibaba/druid/issues/2040
通过这个方法可以解决
注解 spring.aop.proxy-target-class