gpt4 book ai didi

java - Spring MVC 4.0.0.5、Maven 和 Quartz

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:44:01 25 4
gpt4 key购买 nike

我一直在努力让 quartz 在我们正在创建的这个网络应用程序上工作,但一直未能做到。我已经尝试过 1.8.5、1.8.6、2.2.0、2.2.1、2.1.4.. 我只是不知道该怎么做,他们都不想正确构建。我很确定我做的其他一切都是正确的。我真的需要一些帮助来解决这个问题。我还没有对它做任何花哨的事情,我只是想让它现在运行!我把我的文件放在下面。

POM文件:

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

spring-quartz.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="QuartzService" class="org.webapp.service.QuartzService" />

<bean id="myJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="QuartzService" />
<property name="targetMothod" value="printCurrentTime" />
</bean>

<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="myJob" />
<property name="repeatInterval" value="5000" />
<property name="startDelay" value="1000" />
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name="jobDetails">
<list>
<ref bean="myJob" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="simpleTrigger" />
</list>
</property>
</bean>

Controller :

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class QuartzController {
public static void main(String[] args) throws Exception {
new ClassPathXmlApplicationContext("spring-quartz.xml");
}
}

服务:

import org.webapp.repository.QuartzRepository;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

public class QuartzService extends QuartzJobBean{
private QuartzRepository myTask;

public void setMyTask(QuartzRepository myTask){
this.myTask = myTask;
}

@Override
protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {
myTask.printCurrentTime();
}
}

repo 类:

import org.apache.log4j.Logger;

import java.util.Calendar;

public class QuartzRepository {

protected static Logger logger = Logger.getLogger("repository");

public void printCurrentTime() {
logger.error("BITCH: " + Calendar.getInstance().getTime());
}
}

我很确定这就是一切。我不断收到的错误是:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project: Compilation failure: Compilation failure:
[ERROR] /C:/src/main/java/org/webapp/service/QuartzService.java:[9,45] package org.springframework.scheduling.quartz does not exist
[ERROR] /C:/src/main/java/org/webapp/service/QuartzService.java:[11,36] cannot find symbol
[ERROR] symbol: class QuartzJobBean
[ERROR] /C:/src/main/java/org/webapp/service/QuartzService.java:[18,5] method does not override or implement a method from a supertype
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:858)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more

最佳答案

你必须添加“spring-context-support”作为依赖,而不仅仅是“spring-context”

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.2.6.RELEASE</version>
</dependency>

关于java - Spring MVC 4.0.0.5、Maven 和 Quartz,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29583634/

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