刚刚提了一个 issue
然后为了方便老哥们看,我直接复制过来
I use the Spring Boot v2.0.5.RELEASE which depends on Spring 5.0.9 Release
I got a problem when I need both MethodValidationPostProcessor
and Scheduled
here's the detail.
When I just use Scheduled
like below
@SpringBootApplication
@EnableConfigServer
@EnableScheduling
public class SpringConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringConfigServerApplication.class, args);
}
@Scheduled(fixedDelay = 5000)
public void test() {
System.out.println("Demo");
}
}
the scheduler works well as what I want. But when I add a MethodValidationPostProcessor like below
@SpringBootApplication
@EnableConfigServer
@EnableScheduling
public class SpringConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringConfigServerApplication.class, args);
}
@Bean
public MethodValidationPostProcessor methodValidationPostProcessor() {
MethodValidationPostProcessor methodValidationPostProcessor = new MethodValidationPostProcessor();
methodValidationPostProcessor.setProxyTargetClass(true);
return methodValidationPostProcessor;
}
@Scheduled(fixedDelay = 5000)
public void test() {
System.out.println("Demo");
}
}
the scheduler doesn't work. I have already checked the org.springframework.scheduling.config.ScheduledTaskRegistrar
, the scheduler inits as well, but there isn't any task in all of the task variables such as fixedRateTasks
, fixedDelayTasks
and etc.
Is there any chance that we can use MethodValidationPostProcessor and the scheduler together?
1
chendy 2019-12-09 16:31:38 +08:00
目测是一个 bug
但是只要把那个方法挪到别的类里就能正常工作了 另外 SpringBoot 有自动配置一个`MethodValidationPostProcessor` |
2
ManjusakaL OP @chendy 其余的类我试过貌似也不可以😂😂
|
3
ManjusakaL OP @chendy 试了下,移动到其余的类是可以的,不过不能用 Autowired 注入。。
|
4
ManjusakaL OP @chendy 查到原因了,官方的回复
the post-processor method should be static to prevent early initialization of the whole chain. You also should have a message in the log stating that some beans couldn't be post-processed. This is the reason why scheduling doesn't work with such arrangement. If moving it to static doesn't fix the problem, please share a small sample (zip or github repo) we can run ourselves and we can reconsider. |
5
zhazi 2019-12-09 19:56:05 +08:00 via Android
应该是生命周期处理上出现问题,比 post processor 先行注册了,导致生命周期组件出现问题
|
6
ManjusakaL OP @zhazi 嗯,有可能,具体我还得看看文档
|
7
Aruforce 2019-12-09 20:39:09 +08:00 via Android
Postprocessor 好像有个 order 接口指定执行顺序…你可以看下 AbstractApplicationContext 这个类的 refresh 的代码…是对象工厂初始化流程代码…beanfactorypost processor 和 Bean Post processor…好像都有 ordered 接口…
|
8
ManjusakaL OP @Aruforce 我去看看,谢谢老哥
|