Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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
Java SpringBootQuartz:jdbc表总是初始化的_Java_Spring_Spring Boot_Spring Data Jpa_Quartz Scheduler - Fatal编程技术网

Java SpringBootQuartz:jdbc表总是初始化的

Java SpringBootQuartz:jdbc表总是初始化的,java,spring,spring-boot,spring-data-jpa,quartz-scheduler,Java,Spring,Spring Boot,Spring Data Jpa,Quartz Scheduler,我们在spring引导应用程序中使用quartz。 为了存储作业信息,我使用了JDBCStore。 在application.properties文件中,我有以下内容: spring.quartz.job-store-type=jdbc spring.quartz.jdbc.initialize-schema=always 但每次重启后,表都会被初始化,所有存储的信息都会丢失。 如果我将spring.quartz.jdbc.initialize-schema更改为never,则在创建表时会出现

我们在spring引导应用程序中使用quartz。 为了存储作业信息,我使用了JDBCStore。 在
application.properties
文件中,我有以下内容:

spring.quartz.job-store-type=jdbc
spring.quartz.jdbc.initialize-schema=always
但每次重启后,表都会被初始化,所有存储的信息都会丢失。 如果我将spring.quartz.jdbc.initialize-schema更改为never,则在创建表时会出现异常

我不想在重新启动后删除石英表数据。 你能帮我吗

问候,,
斯蒂芬

根据文件:

默认情况下,使用 随Quartz库提供的标准脚本。这些脚本会自动删除 现有表,每次重新启动时删除所有触发器。也是 可以通过设置 spring.quartz.jdbc.schema属性

你能做的是:

  • 修改quartz用于创建表的脚本,删除drop table语句,如果不存在,则使用
    创建表…

  • 将语句放入
    src/main/resources
    目录中某个地方的脚本中(假设您使用的是maven)

  • spring.quartz.jdbc.schema
    设置为指向在#2中创建的文件

  • 因为您可以使用任何数据库,所以脚本将是特定于数据库的

    另一种方法是使用flyway/liquibase,并使用上述脚本作为这些管理系统的变更(我个人会这么做)

    剧本-

    例如,mysql就在这里(您希望删除开头的drop table语句,并按照上面的步骤使用自定义初始化脚本):


    我为Spring boot执行了以下步骤,以使其完美运行

    我手动创建了名为“quartz”的模式。然后通过从中复制正确的脚本手动创建所有表

    然后,我在spring引导属性文件中有以下属性:

    spring.quartz.jdbc.initialize-schema=never
    spring.quartz.properties.org.quartz.jobStore.tablePrefix=quartz.QRTZ_
    
    我设置的所有其他属性如下所示:

    #==============================================================
    # QUARTZ Configuration
    #==============================================================
    spring.quartz.job-store-type=jdbc
    spring.quartz.jdbc.initialize-schema=never
    spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
    spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO
    spring.quartz.properties.org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
    spring.quartz.properties.org.quartz.threadPool.threadCount=25
    spring.quartz.properties.org.quartz.threadPool.threadPriority=5
    spring.quartz.properties.org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true
    spring.quartz.properties.org.quartz.jobStore.misfireThreshold=60000
    spring.quartz.properties.org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
    spring.quartz.properties.org.quartz.jobStore.useProperties=false
    spring.quartz.properties.org.quartz.jobStore.tablePrefix=quartz.QRTZ_
    spring.quartz.properties.org.quartz.jobStore.isClustered=true
    spring.quartz.properties.org.quartz.jobStore.clusterCheckinInterval=5000
    

    那么你还期待什么呢。这正是您所指示的操作。为了避免初始化表,我将设置更改为spring.quartz.jdbc.initializeschema=never。但是,我得到了异常,并且没有生成表。谢谢您的建议。我在谷歌上搜索了一下,发现下面的组合是推荐的,而且也有效:spring.quartz.jdbc.initializeschema=never。所以,我想知道为什么它在我的情况下不起作用。我们还需要配置其他东西吗?您必须创建数据库表,如果您将模式设置为“从不”,quarts不会为您创建它。因此,请将其设置为“从不”,然后确保以某种方式创建表格(重新阅读我的答案,了解两种不同的方式如何创建),谢谢。我正在按照你的建议工作。我在Resources中定义了文件quartz_tables.sql。在application.properties中,我给它赋值classpath:/quartz\u tables.sql。但是这个文件没有被提取。你能提供进一步的帮助吗?@Stephan这是一个单独的问题-作为自己的问题提问,并发布更多详细信息。通常,如果给出的答案回答了你的问题,你会将其标记为正确(上面的复选标记)
    #==============================================================
    # QUARTZ Configuration
    #==============================================================
    spring.quartz.job-store-type=jdbc
    spring.quartz.jdbc.initialize-schema=never
    spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
    spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO
    spring.quartz.properties.org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
    spring.quartz.properties.org.quartz.threadPool.threadCount=25
    spring.quartz.properties.org.quartz.threadPool.threadPriority=5
    spring.quartz.properties.org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true
    spring.quartz.properties.org.quartz.jobStore.misfireThreshold=60000
    spring.quartz.properties.org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
    spring.quartz.properties.org.quartz.jobStore.useProperties=false
    spring.quartz.properties.org.quartz.jobStore.tablePrefix=quartz.QRTZ_
    spring.quartz.properties.org.quartz.jobStore.isClustered=true
    spring.quartz.properties.org.quartz.jobStore.clusterCheckinInterval=5000