|
|
|
@ -8,9 +8,10 @@ import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.BeansException;
|
|
|
|
import org.springframework.beans.BeansException;
|
|
|
|
import org.springframework.beans.factory.DisposableBean;
|
|
|
|
import org.springframework.beans.factory.DisposableBean;
|
|
|
|
import org.springframework.beans.factory.SmartInitializingSingleton;
|
|
|
|
import org.springframework.beans.factory.SmartInitializingSingleton;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.config.BeanDefinition;
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
import org.springframework.context.ApplicationContextAware;
|
|
|
|
import org.springframework.context.ApplicationContextAware;
|
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
|
import org.springframework.context.support.GenericApplicationContext;
|
|
|
|
import org.springframework.core.MethodIntrospector;
|
|
|
|
import org.springframework.core.MethodIntrospector;
|
|
|
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
|
|
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
|
|
|
|
|
|
|
|
|
|
|
@ -33,9 +34,6 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void afterSingletonsInstantiated() {
|
|
|
|
public void afterSingletonsInstantiated() {
|
|
|
|
|
|
|
|
|
|
|
|
// init JobHandler Repository
|
|
|
|
|
|
|
|
/*initJobHandlerRepository(applicationContext);*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init JobHandler Repository (for method)
|
|
|
|
// init JobHandler Repository (for method)
|
|
|
|
initJobHandlerMethodRepository(applicationContext);
|
|
|
|
initJobHandlerMethodRepository(applicationContext);
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,29 +54,11 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
|
|
|
|
super.destroy();
|
|
|
|
super.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*private void initJobHandlerRepository(ApplicationContext applicationContext) {
|
|
|
|
* init job handler from method
|
|
|
|
if (applicationContext == null) {
|
|
|
|
*
|
|
|
|
return;
|
|
|
|
* @param applicationContext applicationContext
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// init job handler action
|
|
|
|
|
|
|
|
Map<String, Object> serviceBeanMap = applicationContext.getBeansWithAnnotation(JobHandler.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (serviceBeanMap != null && serviceBeanMap.size() > 0) {
|
|
|
|
|
|
|
|
for (Object serviceBean : serviceBeanMap.values()) {
|
|
|
|
|
|
|
|
if (serviceBean instanceof IJobHandler) {
|
|
|
|
|
|
|
|
String name = serviceBean.getClass().getAnnotation(JobHandler.class).value();
|
|
|
|
|
|
|
|
IJobHandler handler = (IJobHandler) serviceBean;
|
|
|
|
|
|
|
|
if (loadJobHandler(name) != null) {
|
|
|
|
|
|
|
|
throw new RuntimeException("xxl-job jobhandler[" + name + "] naming conflicts.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
registJobHandler(name, handler);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initJobHandlerMethodRepository(ApplicationContext applicationContext) {
|
|
|
|
private void initJobHandlerMethodRepository(ApplicationContext applicationContext) {
|
|
|
|
if (applicationContext == null) {
|
|
|
|
if (applicationContext == null) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
@ -87,12 +67,28 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
|
|
|
|
String[] beanDefinitionNames = applicationContext.getBeanNamesForType(Object.class, false, false); // allowEagerInit=false, avoid early initialization
|
|
|
|
String[] beanDefinitionNames = applicationContext.getBeanNamesForType(Object.class, false, false); // allowEagerInit=false, avoid early initialization
|
|
|
|
for (String beanDefinitionName : beanDefinitionNames) {
|
|
|
|
for (String beanDefinitionName : beanDefinitionNames) {
|
|
|
|
|
|
|
|
|
|
|
|
// filter system bean
|
|
|
|
// skip system bean
|
|
|
|
if (isSystemBean(beanDefinitionName)) {
|
|
|
|
if (isSystemBean(beanDefinitionName)) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// get bean
|
|
|
|
// skip lazy bean
|
|
|
|
|
|
|
|
if (applicationContext instanceof GenericApplicationContext genericApplicationContext) {
|
|
|
|
|
|
|
|
if (!genericApplicationContext.containsBeanDefinition(beanDefinitionName)) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// valid lazy bean
|
|
|
|
|
|
|
|
BeanDefinition beanDefinition = genericApplicationContext.getBeanDefinition(beanDefinitionName);
|
|
|
|
|
|
|
|
if (beanDefinition.isLazyInit()) {
|
|
|
|
|
|
|
|
logger.debug("xxl-job bean-definition scan, skip lazy-init bean:{}", beanDefinitionName);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// load bean
|
|
|
|
|
|
|
|
Object bean = applicationContext.getBean(beanDefinitionName);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
skip lazy bean2
|
|
|
|
Object bean = null;
|
|
|
|
Object bean = null;
|
|
|
|
Lazy onBean = applicationContext.findAnnotationOnBean(beanDefinitionName, Lazy.class);
|
|
|
|
Lazy onBean = applicationContext.findAnnotationOnBean(beanDefinitionName, Lazy.class);
|
|
|
|
if (onBean!=null){
|
|
|
|
if (onBean!=null){
|
|
|
|
@ -101,6 +97,7 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
|
|
|
|
}else {
|
|
|
|
}else {
|
|
|
|
bean = applicationContext.getBean(beanDefinitionName);
|
|
|
|
bean = applicationContext.getBean(beanDefinitionName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// filter method
|
|
|
|
// filter method
|
|
|
|
Map<Method, XxlJob> annotatedMethods = null; // referred to :org.springframework.context.event.EventListenerMethodProcessor.processBean
|
|
|
|
Map<Method, XxlJob> annotatedMethods = null; // referred to :org.springframework.context.event.EventListenerMethodProcessor.processBean
|
|
|
|
@ -149,13 +146,4 @@ public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationC
|
|
|
|
return applicationContext;
|
|
|
|
return applicationContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
BeanDefinitionRegistryPostProcessor
|
|
|
|
|
|
|
|
registry.getBeanDefine()
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
|
|
|
|
|
|
|
|
this.registry = registry;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
* */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|