Spring启动api之前将数据加载到sql

问题描述 投票:0回答:2

我正在尝试为电子邮件调度实现石英调度程序。所以一切都已建立,但主要问题是石英三重奏的倾销。下载postgre脚本之后我mannualy使用'\ i path to scrpt'从终端运行它。我希望那个spring在api启动时自动运行这个脚本。

我尝试将此脚本复制到资源并尝试更改某些属性但尚无效

# Hibernate properties
    spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
    spring.jpa.show-sql=false
    spring.jpa.properties.hibernate.format_sql=true
    spring.jpa.hibernate.ddl-auto= update
    spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation = false

    # QuartzProperties
    spring.quartz.job-store-type = jdbc
    org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
    spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
    #spring.quartz.jdbc.schema=classpath:org/quartz/impl/jdbcjobstore/tables_postgres.sql
    org.quartz.jobStore.dataSource = default
    spring.quartz.properties.org.quartz.threadPool.threadCount = 5
java postgresql spring-boot quartz-scheduler
2个回答
0
投票

如果你使用的是spring boot,你可以使用@EnableScheduling inna你的Application类,如下所示:

@SpringBootApplication
@EnableScheduling
public class Application {
public static void main(String[] args){
    SpringApplication.run(Application.class, args); 
}

}

然后,您可以在类作业中使用@Scheduled,例如:@Component public class MyJob {

    @Scheduled(fixedDelay= 1000 * 60 * 24)
    public void execute() {
       System.out.println("Your job here!");
    }
}

如果你想在开始时延迟使用initialDelay。


0
投票

解决了,添加prop:spring.datasource.initialization-mode = always。我只需要在固定的时间做一次工作,所以我需要使用石英。

© www.soinside.com 2019 - 2024. All rights reserved.