xxl-job
xxl-job copied to clipboard
优化 spring 适配 lazy加载 修改原来的直接扫@lazy注解,spring可以不只通过@lazy这一种方式
What kind of change does this PR introduce? (check at least one)
- [x] Bugfix
- [ ] Feature
- [ ] Code style update
- [ ] Refactor
- [ ] Build-related changes
- [ ] Other, please describe:
The description of the PR:
Other information:
我也遇到这样的问题了,我通过AOP懒加载了整个包而不是lazy注解,xxl-job启动的时候强制加载所有bean,导致应用启动速度耗费几十倍的时间
我本机写JobConfig的时候重写了XxlJobSpringExecutor,使用下面方法处理了懒加载问题,关于NoSuchBeanDefinitionException异常就直接捕获了。 GenericApplicationContext ctx = (GenericApplicationContext)applicationContext; BeanDefinition beanDefinition =ctx.getBeanDefinition(beanDefinitionName); boolean lazyInit = ctx.getBeanDefinition(beanDefinitionName).isLazyInit(); 处理完这个问题后发现应用启动依旧很慢,原来是又初始化了mybatisplus的mapper,mp的mapper多到一定程度后初始化就会非常慢,我又不得不采用了下面措施避免初始化mapper。总之,GclJobSpringExecutor对spring的侵入还是挺狠的,考虑重新一下实现方式~~ boolean isMapper= beanClassName != null && beanClassName.startsWith("org.mybatis.spring.mapper.MapperFactoryBean"); if (lazyInit||isMapper) { log.debug("LazyInit or Mapper bean:"+beanDefinitionName); continue; }
是否可以通过bean定义进行判断
这个PR和我回复的都是通过bean定义来处理的。其实我们都可以根据自己项目的情况写自定义的执行器,这样就不用考虑xxl-job写的那个spring执行器本来的样子了。