1. 程式人生 > >lts任務無法執行到tasktracker問題, 'LTS_JobRunnerDispatcher'

lts任務無法執行到tasktracker問題, 'LTS_JobRunnerDispatcher'

開發十年,就只剩下這套架構體系了! >>>   

表現出來的異常程式碼如下:

	... 11 more
[saas-wis-equipment] 2019-03-14 19:30:48 DEBUG [pool-5-thread-5] com.github.ltsopensource.core.logger.slf4j.Slf4jLogger.debug(40) |  [LTS] Job execute error : {"cron":true,"cronExpression":"*/15 * * * * ?","extParams":{"type":"AAA"},"maxRetryTimes":0,"needFeedback":true,"priority":100,"relyOnPrevCycle":false,"repeatCount":0,"repeatInterval":0,"repeatable":false,"replaceOnExist":false,"submitNodeGroup":"WisEquipmentJobClient","taskId":"AAA_0314-192945","taskTrackerNodeGroup":"WisEquipmentTaskTracker_11","triggerTime":1552562985000}, time: 0, Error creating bean with name 'LTS_JobRunnerDispatcher': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.isesol.wis.equipment.task.job.JobRunnerDispatcher, lts version: 1.6.8-SNAPSHOT, current host: 10.1.60.125
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LTS_JobRunnerDispatcher': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.isesol.wis.equipment.task.job.JobRunnerDispatcher
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1116) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1060) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:325) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]
	at com.github.ltsopensource.spring.TaskTrackerAnnotationFactoryBean$1.newRunner(TaskTrackerAnnotationFactoryBean.java:139) ~[lts-spring-1.6.8-SNAPSHOT.jar:?]
	at com.github.ltsopensource.tasktracker.runner.JobRunnerDelegate.run(JobRunnerDelegate.java:84) [lts-tasktracker-1.6.8-SNAPSHOT.jar:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_111]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_111]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.isesol.wis.equipment.task.job.JobRunnerDispatcher
	at sun.reflect.GeneratedConstructorAccessor74.newInstance(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_111]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_111]
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1108) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
	... 11 more

分析原因是:

public interface TaskTypeConstant{

	enum TaskType{
		TEST_TRIGGER("TestTrigger2");
		public String typeName;

		TaskType(final String name){
			this.typeName=name;
		}
	}
	
}
    static {
        JOB_RUNNER_MAP.put("hello", new TestTriggerService()); //1
        JOB_RUNNER_MAP.put(TaskType.TEST_TRIGGER.typeName,  SpringContextHolder.getBean(TestTriggerService.class));//2
        JOB_RUNNER_MAP.put(TaskTypeConstant.TaskType.EQUIPMENT_APP_DATA.typeName, SpringContextHolder.getBean(EquipmentAppDataService.class));//3
    }

看上面程式碼 static 塊裡面的第三步出了問題

最終發現

因為 EquipmentAppDataService.class 沒有加@Service註解,不在bean容器。 SpringContextHolder.getBean方法執行導致異常,從而影響到該類不能正