I made this code using gpt, it's a maven project. Here is the code -
App.java -
package com.example;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
//I am not sure what do do with this file
PracticeApplication.java
package com.example;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class PracticeApplication extends QuartzJobBean
{
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException
{
System.out.println("Hello");
}
}
QuartzSchedularConfig.java
package com.example;
import org.quartz.JobDetail;
import org.quartz.SimpleTrigger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
@Configuration
public class QuartzSchedulerConfig {
@Autowired
private JobDetail job1; // Autowire the job bean
@Autowired
private SimpleTrigger trigger1; // Autowire the trigger bean
@Bean
public SchedulerFactoryBean schedulerFactoryBean() {
SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
scheduler.setConfigLocation(new ClassPathResource("quartz-config.xml"));
scheduler.setAutoStartup(true);
scheduler.setWaitForJobsToCompleteOnShutdown(true);
// Use the autowired job and trigger
scheduler.setJobDetails(job1);
scheduler.setTriggers(trigger1);
return scheduler;
}
}
quartz-config.xml -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="job1" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.example.PracticeApplication" />
<property name="durability" value="true" />
</bean>
<bean id="trigger1" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="job1" />
<property name="repeatInterval" value="120000" /> <!-- Repeat every 2 minutes -->
<property name="repeatCount" value="0" /> <!-- Repeat indefinitely -->
</bean>`
</beans>
It only runs the App.java file and then code stops.
Its supposed to print Hello every 2 mins.
Now I cant use anything else except for QuartzBeanJob and because thats how the codebase for the actual application is set up.