Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Spring 4/Boot初始化Quartz调度程序_Spring_Quartz Scheduler_Spring Boot_Spring 4 - Fatal编程技术网

使用Spring 4/Boot初始化Quartz调度程序

使用Spring 4/Boot初始化Quartz调度程序,spring,quartz-scheduler,spring-boot,spring-4,Spring,Quartz Scheduler,Spring Boot,Spring 4,我有一个带Spring Boot的Spring 4应用程序- 没有WEBINF/web.xml文件,但是,我想在应用程序启动时初始化。但是,所有使用的示例都在web.xml文件中定义了设置 我可以将这些配置添加到我的应用程序启动配置中吗 @Configuration @ComponentScan @EnableAutoConfiguration public class Application { @Bean public DataSource dataSource() {

我有一个带Spring Boot的Spring 4应用程序-

没有WEBINF/web.xml文件,但是,我想在应用程序启动时初始化。但是,所有使用的示例都在web.xml文件中定义了设置

我可以将这些配置添加到我的应用程序启动配置中吗

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
        @Bean
public DataSource dataSource() {
    DriverManagerDataSource ds = new DriverManagerDataSource();
    ds.setDriverClassName("org.postgresql.Driver");
    ds.setUrl("jdbc:postgresql://localhost/...");
    ds.setUsername("...");
    ds.setPassword("...!");
    return ds;
}
    /** Add configuration to start Quartz here so 
        I can access it throughout the app? **/ 

@Bean
public org.springframework.scheduling.quartz.SchedulerFactoryBean SchedulerFactoryBean(){
    SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
    scheduler.setAutoStartup(true);
    scheduler.setDataSource(dataSource());
    return scheduler;

}

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
更新

了解了SpringFrameworkQuartz bean之后,现在我需要正确地实现数据存储,以便在运行之间恢复作业


我正在使用postgresql+spring数据和hibernate。此配置会在每次运行时重新初始化数据库。HSQL还重新初始化了一些“import.sql”数据。我是否应该创建一个hibernate接口,以便在测试时恢复作业?

您最后提到了HSQL,但您的数据源是PostgreSQL。如果是PostgreSQL,那么spring.jpa.hibernate.ddl-auto的默认设置是none,启动时不会创建或初始化jpa表,所以我有点困惑。顺便说一下,如果您只是在中设置spring.DataSource.*属性,那么就不需要数据源bean。您是否尝试过查看@PostConstruct注释@DaveSyer是的,我将hsqldb添加到我的pom中,它打开了ddl自动设置,而没有考虑它。我应该期望quartz能够像ddl auto一样生成自己的作业存储表,还是必须手动定义它?如果是这样,我就是找不到模式。我将更改配置以使用首选的spring数据方式@user2339071如果我添加@PostContract,我不认为当Quartz尝试连接到数据库时它会改变,是吗?如果您的数据源不是hsqldb,那么ddl auto的默认值应该是“无”。如果不是,也许你有一个旧版本的启动?在任何情况下,您都可以手动将其切换为“无”。关于quartz作业表的主题,我不知道,但我从未见过有人显式地配置模式,所以我假设它会自动创建它。