春天 3 +石英2错误
当我将 Spring 3 与 Quartz 2 一起使用时,我收到以下错误。有人知道原因吗?
错误:
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 [beans.xml]: problem with class file or dependent class; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.JobDetailBean has interface org.quartz.JobDetail as super class
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1253)
Spring 配置文件:
<bean name="job" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="Example.ExampleJob"/>
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="5"/>
</map>
</property>
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="job"/>
<property name="startDelay" value="1000"/>
<property name="repeatInterval" value="5000"/>
</bean>
public class ExampleJob extends QuartzJobBean {
private int timeout;
/**
* Setter called after the ExampleJob is instantiated
* with the value from the JobDetailBean (5)
*/
public void setTimeout(int timeout) {
this.timeout = timeout;
}
@Override
protected void executeInternal(JobExecutionContext ctx)
throws JobExecutionException {
*****
}
}
I received the error below when I use Spring 3 with Quartz 2. Does anyone knows the reason?
Error:
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 [beans.xml]: problem with class file or dependent class; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.JobDetailBean has interface org.quartz.JobDetail as super class
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1253)
Spring config file:
<bean name="job" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="Example.ExampleJob"/>
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="5"/>
</map>
</property>
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="job"/>
<property name="startDelay" value="1000"/>
<property name="repeatInterval" value="5000"/>
</bean>
public class ExampleJob extends QuartzJobBean {
private int timeout;
/**
* Setter called after the ExampleJob is instantiated
* with the value from the JobDetailBean (5)
*/
public void setTimeout(int timeout) {
this.timeout = timeout;
}
@Override
protected void executeInternal(JobExecutionContext ctx)
throws JobExecutionException {
*****
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果使用 Spring 3.1,
请将 SimpleTriggerBean 替换为 SimpleTriggerFactoryBean
在 3.1 版本中,Spring 为 crontrigger 和 simpletrigger
Update 创建了 Factory 类:
感谢 Osy(对下面的评论进行投票)
If you use Spring 3.1,
Replace the SimpleTriggerBean with SimpleTriggerFactoryBean
In the 3.1 release, Spring has created Factory classes for crontrigger and simpletrigger
Update:
Credit to Osy (vote on the comment below)
最后我检查了一下,Spring 不支持 Quartz 2。要么看看最新的 Spring 版本是否添加了上述支持,要么尝试降级到 Quartz 1.8.x。
Last I checked, Spring doesn't have support for Quartz 2. Either have a look to see if the most recent Spring builds have added said support, or try downgrading to Quartz 1.8.x.
根据 3.1.0.RC1 变更日志,Spring 3.1 支持石英 2.x。
对于每个
{Type}TriggerBean
,现在都有一个可用于设置触发器的{Type}TriggerBeanFactory
。在您的情况下,这将是SimpleTriggerFactoryBean
摘录
旁注
您可能还需要添加 org.springframework.transaction 依赖项,具体取决于您使用的触发器类型:
我们需要它在使用
CronTriggerFactoryBean
触发器。According to the 3.1.0.RC1 Change Log, Spring 3.1 has support for Quartz 2.x.
For every
{Type}TriggerBean
there is now a{Type}TriggerBeanFactory
which can be used to setup triggers. In your case this would beSimpleTriggerFactoryBean
Excerpt
Sidenote
You might also need to add the org.springframework.transaction dependency, depending on which type of trigger you are using:
We needed it for migration to Quartz 2 in a configuration using
CronTriggerFactoryBean
triggers.如果您使用 Spring 3.x & Quartz 2.1.x…
然后在您的配置文件中只进行两处更改
第一:对于简单触发器,
使用
class=”org.springframework.scheduling.quartz.SimpleTriggerFactoryBean”>
而不是class=”org.springframework.scheduling.quartz.SimpleTriggerBean”>
第二个:用于 Cron 触发器
使用
class=”org.springframework.scheduling.quartz.CronTriggerFactoryBean”
而不是class=”org.springframework.scheduling.quartz.CronTriggerBean”
If You are using Spring 3.x & Quartz 2.1.x…
Then do only two changes IN YOUR configuration file
1st : for Simple Trigger
Use
class=”org.springframework.scheduling.quartz.SimpleTriggerFactoryBean”>
instead ofclass=”org.springframework.scheduling.quartz.SimpleTriggerBean”>
2nd : for Cron Trigger
use
class=”org.springframework.scheduling.quartz.CronTriggerFactoryBean”
instead ofclass=”org.springframework.scheduling.quartz.CronTriggerBean”
就我而言,问题是由重复的石英库引起的。我在 pom.xml 中包含了排除项。
In my case, the problem was result from duplicate quartz lib. I have include a exclusion in pom.xml.