gpt4 book ai didi

java - 在 Spring Web 应用程序中找不到类 [org.springframework.scheduling.quartz.SchedulerFactoryBean]

转载 作者:行者123 更新时间:2023-12-02 01:56:07 28 4
gpt4 key购买 nike

我正在尝试在 Spring 的 Web 应用程序中构建一个调度程序。我使用maven来处理所有的依赖关系。我已将以下 bean 放入 XML 中

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="configLocation" value="classpath:quartz.properties" />
</bean>

在 web.xml 文件中,我有以下内容(来自教程):

<context-param>
<param-name>quartz:config-file</param-name>
<param-value>quartz.properties</param-value>
</context-param>
<context-param>
<param-name>quartz:shutdown-on-unload</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>quartz:wait-on-shutdown</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>quartz:start-scheduler-on-load</param-name>
<param-value>true</param-value>
</context-param>

在我的 pom.xml 中,我再次添加了教程建议的内容

    <!-- Quartz API -->
<dependency>
<groupId>opensymphony</groupId>
<artifactId>quartz</artifactId>
<version>1.6.3</version>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>

<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.logging</artifactId>
<version>1.1.1</version>
</dependency>

<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>

<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.2.0</version>
</dependency>

我还定义了一个quartz.properties文件

org.quartz.plugin.jobInitializer.class = 
org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = quartz_jobs.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 10
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool

当然还有我的quartz_jobs.xml 文件:

<?xml version='1.0' encoding='utf-8'?>
<job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.quartz-
scheduler.org/xml/JobSchedulingData http://www.quartz-
scheduler.org/xml/job_scheduling_data_1_8.xsd"
version="1.8">

<schedule>
<job>
<name>myJob</name>
<group>MYJOB_GROUP</group>

<description>My job description</description>
<job-class>com.blah.blah.myJob</job-class>

</job>

<trigger>
<cron>
<name>myTrigger</name>
<group>MYTRIGGER_GROUP</group>
<job-name>myJob</job-name>

<job-group>MYJOB_GROUP</job-group>
<!-- trigger every 5 seconds -->
<cron-expression>0/5 * * * * ?</cron-expression>

</cron>
</trigger>
</schedule>

然后我创建了一个调度程序和一个作业类(类似于基本教程的类)。我的问题是,当我运行它时,我收到 3 个错误:

2018-09-10 14:52:23,636 - ERROR - [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.scheduling.quartz.SchedulerFactoryBean] for bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in class path resource ...

Sep 10, 2018 2:52:23 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.scheduling.quartz.SchedulerFactoryBean] for bean with name
'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in class path resource ...

Quartz Initializer Servlet loaded, initializing Scheduler...
Sep 10, 2018 2:52:23 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.quartz.ee.servlet.QuartzInitializerListener
java.lang.NoClassDefFoundError: javax/transaction/UserTransaction

经过更多记录后,它显示Quartz Scheduler 成功关闭。。我不知道发生了什么,我对我所做的事情不是很有信心,因为我并不真正了解 Java spring 及其配置。有人能弄清楚我错过了什么吗?

编辑:通过在我的 pom.xml 中添加 javax.transaction 解决了第三个错误

EDIT2:这是完整的堆栈跟踪:

2018-09-10 16:28:10,698 - ERROR - [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.scheduling.quartz.SchedulerFactoryBean] for bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in class path resource [ctx-core/my.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.SchedulerFactoryBean
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1278)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:575)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1347)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:913)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:617)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5017)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5531)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.SchedulerFactoryBean
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1722)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1573)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:265)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:419)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1299)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1270)
... 18 more
Sep 10, 2018 4:28:10 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.scheduling.quartz.SchedulerFactoryBean] for bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in class path resource [ctx-core/my.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.SchedulerFactoryBean
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1278)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:575)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1347)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:913)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:617)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5017)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5531)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.SchedulerFactoryBean
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1722)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1573)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:265)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:419)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1299)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1270)
... 18 more
Quartz Initializer Servlet loaded, initializing Scheduler...
2018-09-10 16:28:10,730 - INFO - [org.quartz.core.SchedulerSignalerImpl] - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
2018-09-10 16:28:10,730 - INFO - [org.quartz.core.QuartzScheduler] - Quartz Scheduler v.1.6.3 created.
2018-09-10 16:28:10,730 - INFO - [org.quartz.simpl.RAMJobStore] - RAMJobStore initialized.
2018-09-10 16:28:10,730 - INFO - [org.quartz.impl.StdSchedulerFactory] - Quartz scheduler 'QuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties'
2018-09-10 16:28:10,730 - INFO - [org.quartz.impl.StdSchedulerFactory] - Quartz scheduler version: 1.6.3
2018-09-10 16:28:10,730 - INFO - [org.quartz.core.QuartzScheduler] - Scheduler QuartzScheduler_$_NON_CLUSTERED started.
Scheduler has been started...
Storing the Quartz Scheduler Factory in the servlet context at key: org.quartz.impl.StdSchedulerFactory.KEY
Sep 10, 2018 4:28:10 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Sep 10, 2018 4:28:10 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/myproject] startup failed due to previous errors
2018-09-10 16:28:10,734 - INFO - [org.quartz.core.QuartzScheduler] - Scheduler QuartzScheduler_$_NON_CLUSTERED shutting down.
2018-09-10 16:28:10,734 - INFO - [org.quartz.core.QuartzScheduler] - Scheduler QuartzScheduler_$_NON_CLUSTERED paused.
2018-09-10 16:28:10,734 - INFO - [org.quartz.core.QuartzScheduler] - Scheduler QuartzScheduler_$_NON_CLUSTERED shutdown complete.
Quartz Scheduler successful shutdown.

最佳答案

您错过了类路径中的 javax.trasaction API,如消息所述:

java.lang.NoClassDefFoundError: javax/transaction/UserTransaction

添加

<!-- https://mvnrepository.com/artifact/javax.transaction/javax.transaction-api -->
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.3</version>
</dependency>

作为依赖关系,应该解决异常。

另一个问题是缺少类org.springframework.scheduling.quartz.SchedulerFactoryBean

还添加

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>

关于java - 在 Spring Web 应用程序中找不到类 [org.springframework.scheduling.quartz.SchedulerFactoryBean],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52259625/

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