gpt4 book ai didi

java - InstantiationError : org. quartz.JobDetail 使 tomcat9 在 linux 中启动失败但在 windows 中正常

转载 作者:太空宇宙 更新时间:2023-11-04 11:49:49 29 4
gpt4 key购买 nike

我有一个在 spring 4 上开发并在 tomcat 7(使用 jdk8)中运行的 restful api 应用程序现在我尝试将它部署到 tomcat 9(使用 jdk8 构建和运行),构建的 war 文件没有任何问题。但是linux下的tomcat 9启动失败,错误是:

17:44:02:821 WARN [XmlWebApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ediFeedTask' defined in class path resource [spring-scheduler.xml]: Invocation of init method failed; nested exception is java.lang.InstantiationError: org.quartz.JobDetail 17:44:02:839 ERROR [ContextLoader] - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ediFeedTask' defined in class path resource [spring-scheduler.xml]: Invocation of init method failed; nested exception is java.lang.InstantiationError: org.quartz.JobDetail at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.2.9.RELEASE.jar:4.2.9.RELEASE]

基本上它未能实例化spring quartz xml中定义的bean。因为如果我在我的 spring-scheduler.xml 中注释掉所有的 beans 定义,应用程序就会成功启动。这些 bean 都是预定的作业。

但我不明白为什么 tomcat9 在为 quartz 调度程序实例化 bean 时遇到问题。它很好地在其他 xml 中实例化 beans,例如 api-config.xml 或 spring-controller.xml。

最奇怪的是,同一个war文件在windows tomcat 9中部署启动成功,在linux(ubuntu,deepin)中的tomcat 8和9中却失败了,有没有人有任何线索?

下面是我的spring-scheduler.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="ediFeedJob" class="com.ai.api.job.EDIFeedJob" />
<bean id="ediFeedTask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="concurrent" value="false" />
<property name="targetObject" ref="ediFeedJob" />
<property name="targetMethod" value="execute" />
</bean>
<bean id="ediFeedCronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="ediFeedTask" />
<property name="cronExpression" value="0 2 * * * ?"/>
</bean>
<bean id="startQuartz" lazy-init="false"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="ediFeedCronTrigger" />
</list>
</property>
</bean>
</beans>

最佳答案

实际上这是一个 maven 依赖问题。它不像我们通常看到的那样明显是“找不到 XXX 类”,但在这种情况下它会提示“InstantiationError: org.quartz.JobDetail”——所以我们可以假设 spring 本身有问题。

检查 maven 依赖项中的冲突后,我可以看到引用了 spring-beans 2.0.3,而通常它至少应该比 4.0 更新。所以排除掉

<dependency>
<groupId>org.springmodules</groupId>
<artifactId>spring-modules-jakarta-commons</artifactId>
<version>${spring.modules.jakarta.commons.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-support</artifactId>
</exclusion>
</exclusions>

然后问题就解决了。

关于java - InstantiationError : org. quartz.JobDetail 使 tomcat9 在 linux 中启动失败但在 windows 中正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56393118/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com