我迁移了这段代码:
import org.joda.time.DateTime;
@Entity
@Table(name = "purchases")
@Getter
@Setter
public class Purchases {
@Column(name = "purchase_time")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime purchaseTime;
}
Run Code Online (Sandbox Code Playgroud)
到这段代码:
import java.time.ZonedDateTime;
@Entity
@Table(name = "purchases")
@Getter
@Setter
public class Purchases {
@Column(name = "purchase_time")
private ZonedDateTime purchaseTime;
}
Run Code Online (Sandbox Code Playgroud)
现在我收到错误:
2024-01-24 17:20:00.219 ERROR 1 --- [eduler_Worker-1] .a.p.g.i.s.ProcessPendingPurchasesJob : Failed to start/complete pending job.
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [2023-12-25T17:19:54.622Z] did not match expected type [java.time.ZonedDateTime (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [2023-12-25T17:19:54.622Z] did not match expected type …Run Code Online (Sandbox Code Playgroud) 此应用程序必须执行与Web服务的连接,获取数据,将其保存在数据库中.每小时24/7.在java中创建这样一个应用程序最有效的方法是什么?
应该如何运行 - 作为系统应用程序还是作为Web应用程序?
我在我的应用程序中运行了以下Quartz作业:
class ScraperJob {
def scraperService
static triggers = {
cron name: 'scraperTrigger', cronExpression: "0 0 * * * ?" // run every minute
}
def execute(){
try {
scraperService.storing()
log.info "${new Date()} - Scraping went smoothly."
}
catch(IOException) { // Connexion problem
log.error "${new Date()} - Method: parsing >> Connexion down or interrupted while parsing !"
}
catch(SAXException) { // Any SAXParser exception
log.error "${new Date()} - Method: parsing >> Parser error."
}
finally { // if not closed, …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring的SchedulerFactoryBean在基于Spring的Java应用程序中运行一些Quartz作业.目前,这是一个开发中的单实例应用程序,但是一旦我们开始横向扩展,我们就会想要使用基于jdbc的JobStore for Quartz,因此只有一个应用程序将运行给定的作业.
现在,SchedulerFactoryBean配置如下:
<bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name="taskExecutor" ref="taskExecutor"/>
<property name="triggers">
<list>
<!-- a bunch of triggers here -->
</list>
<property name="applicationContextSchedulerContextKey">
<value>applicationContext</value>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
使用基于jdbc的JobStore,它看起来像这样
<bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name="dataSource" ref="mysqlJobDataSource"/>
<property name="taskExecutor" ref="taskExecutor"/>
<property name="triggers">
<list>
<!-- a bunch of triggers here -->
</list>
</property>
<property name="applicationContextSchedulerContextKey">
<value>applicationContext</value>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
<!-- and a bunch of other quartz props -->
</props>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想继续为开发人员使用默认的RAMJobStore版本(第一个),但是对于已部署的环境使用jdbc版本.但是,似乎没有一种非常好的方法可以通过像属性之类的东西在两者之间进行切换,因为jdbc存储涉及更多的配置,并且在SchedulerFactoryBean上仅存在dataSource属性意味着它尝试基于JDBC的作业商店.
此外,由于SchedulerFactoryBean是一个初始化bean,初始化基本上开始运行所有作业,所以我不能将配置文件中定义的那些bean加载到spring上下文中,这意味着我将运行并行作业.
我也读过这个答案,但这种情况不同之处在于我正在处理两个不应该同时在同一个上下文中的InitializingBeans.
配置SchedulerFactoryBean这两种配置之间的最简单方法是什么?
我在servlet.xml中有当前作业和触发器
<bean id="actualizacionAsistencias" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="asistenciasManager" />
<property name="targetMethod" value="run" />
</bean?
<bean id="asistenciasTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="actualizacionAsistencias" />
<property name="cronExpression" value="0 1 1 * * ?" />
</bean>
Run Code Online (Sandbox Code Playgroud)
有没有办法添加参数?我需要方法'run'在执行时重新接收'true'(布尔值).
我正在尝试使用Quartz.NET安排一些工作,但我无法让它工作.我尝试了以下代码,但在达到指定时间时没有任何反应.
public void Test()
{
ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
IScheduler scheduler = schedulerFactory.GetScheduler();
IJobDetail jobDetail = JobBuilder.Create<SatellitePaymentGenerationJob>()
.WithIdentity("TestJob")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.ForJob(jobDetail)
.WithCronSchedule("0 26 18 * * ?")
.WithIdentity("TestTrigger")
.StartNow()
.Build();
scheduler.ScheduleJob(jobDetail, trigger);
scheduler.Start();
}
Run Code Online (Sandbox Code Playgroud)
更新:
我也试过以下只是为了确保它不是导致问题的Cron表达式.对我来说也不起作用......
IJobDetail jobDetail = JobBuilder.Create<SatellitePaymentGenerationJob>()
.WithIdentity("TestJob", "TestGroup")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.ForJob(jobDetail)
.WithSimpleSchedule(x=> x.RepeatForever().WithIntervalInSeconds(10).WithMisfireHandlingInstructionFireNow())
.StartAt(new DateTimeOffset(DateTime.UtcNow.AddSeconds(10)))
.WithIdentity("TestTrigger", "TestGroup")
.Build();
scheduler.ScheduleJob(jobDetail, trigger);
scheduler.Start();
Console.WriteLine(DateTime.UtcNow.ToLongTimeString());
Console.WriteLine(trigger.GetNextFireTimeUtc());
Run Code Online (Sandbox Code Playgroud)
请注意,trigger.GetNextFireTimeUtc()返回有效的时间值,但永远不会触发作业.
我哪里做错了?
我正在尝试将Spring中的数据源configure集成到Quartz调度程序中.虽然我从论坛和邮件列表中收集了一些关于如何做到这一点的信息,但我仍然无法构建整篇文章.
我在Spring中配置数据源如下:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/projectA"/>
<property name="lookupOnStartup" value="false"/>
<property name="cache" value="true"/>
<property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
而Quartz-Spring的配置如下:
<jee:jndi-lookup id="quartzDataSource"
lookup-on-startup="false"
proxy-interface="javax.sql.DataSource"
cache="true"
jndi-name="java:jdbc/projectA"/>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
...
<property name="dataSource" ref="quartzDataSource"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
这不是正确的配置,因为我收到以下错误:
[ERROR ] SRVE0283E: Exception caught while initializing context: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in class path resource [job-authentication-spring.xml]: Invocation of init method failed; nested exception is org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.InvalidNameException: java:jdbc/projectA
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
at …Run Code Online (Sandbox Code Playgroud) 我可以在applicationContext.xml中创建一个taskScheduler,并根据该cron属性定期触发我的工作。
我想cron在调度程序启动后更改此表达式(触发时间),这意味着JavaEE应用程序正在运行。
使用Spring 3.XX
如何将我的IJob实现标记为持久?我在quartz .net文档中找不到任何引用,我不使用任何xml作业配置.不应该在接口中有某种属性PersistJobDataAfterExecution,DisallowConcurrentExecution或者布尔属性IJob?
我是Spring Batch框架和石英调度程序的新手.我的任务是使用quartz调度程序动态安排新的Spring Batch作业.所有新的spring批处理作业的条目都在我的数据库中,带有触发器表达式.问题是,对于来自数据库的每个新的Spring批处理作业,我们需要将它包装在quartz的调度程序作业中.因此意味着许多批量作业类应该在那里包装它们并由石英调度程序运行.
quartz将所有作业和触发器条目存储到自己的数据库表中.我在配置文件中配置.这项工作永远是石英的工作,而不是春季批量工作.这是我的主要方法,在这里我将编写我的数据库连接代码,以找出新的弹簧作业名称和触发器表达式,并将它们与石英计划程序绑定
public static void main(String[] args) {
try {
ApplicationContext context = new ClassPathXmlApplicationContext("quartz-context.xml");
JobLauncher launcher=(JobLauncher) context.getBean("jobLauncher");
JobLocator locator= (JobLocator) context.getBean("jobRegistry");
Scheduler schedulerFactoryBean=(Scheduler) context.getBean("quartzSchedulerFactoryBean");
JobDetail job = newJob(SpringBatchJob.class).withIdentity("myJob001", "group1").build();
Trigger trigger1 =newTrigger().withIdentity("myTrigger001", "group1").startNow().withSchedule(simpleSchedule().withIntervalInSeconds(10).repeatForever()).build();
schedulerFactoryBean.scheduleJob(job, trigger1);
schedulerFactoryBean.start();
} catch (SchedulerException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
在这里我们可以看到jobDetail是quartz作业,其执行方法用于运行spring批处理作业.
springBatchjob.java
public class SpringBatchJob implements Job {
private String jobName;
private String batchJob;
private JobLocator jobLocator;
private JobLauncher jobLauncher;
private File contentDirectory;
private String directoryPath = "inputFiles";
public void init(){
contentDirectory = …Run Code Online (Sandbox Code Playgroud) quartz-scheduler ×10
java ×6
spring ×6
cron ×3
c# ×2
quartz.net ×2
grails ×1
java-time ×1
jdbc ×1
jobs ×1
spring-batch ×1
spring-boot ×1
spring-mvc ×1