在自己电脑上使用Spring触发器,需要用到QuartzJobBean这个类
但是在项目编译时却出现以下提示
Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.scheduling.quartz.JobDetailBean] for bean with name 'job' defined in class path resource [com/syc/springTrigger/beans.xml]: problem with class file or dependent class; nested exception is java.lang.UnsupportedClassVersionError: org/quartz/JobDetail : Unsupported major.minor version 51.0
Caused by: java.lang.UnsupportedClassVersionError: org/quartz/JobDetail : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
一开始以为是jdk的版本问题,但是又想想之前用的spring的项目都是用的好好的就应该不是这个问题了
然后查阅了一下资料,发现是自己引用的qaurtz版本过高了,需要把使用的2.x版本该为1.x版本。改完之后就不会报这个错误了。
但是却报了另外一个错:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in class path resource [com/syc/springTrigger/beans.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/transaction/TransactionException
Caused by: java.lang.NoClassDefFoundError: org/springframework/transaction/TransactionException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2398)
at java.lang.Class.getConstructor0(Class.java:2708)
at java.lang.Class.getDeclaredConstructor(Class.java:1987)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1004)
... 13 more
从错误信息可以直接看到是找不到类,所以在思考,使用spring的触发器是否需要导入spring的transaction的jar包,
果断把spring-tx-3.2.0.RELEASE.jar导入到项目中,果然解决了问题