首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >石英弹簧启动没有DataSource名为“dataSource”

石英弹簧启动没有DataSource名为“dataSource”
EN

Stack Overflow用户
提问于 2022-05-29 07:18:00
回答 1查看 1.5K关注 0票数 3

我有下面的quartz.properties

代码语言:javascript
复制
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.dataSource=dataSource
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.tablePrefix=qrtz_

org.quartz.threadPool.threadCount=1
org.quartz.scheduler.skipUpdateCheck=true
org.quartz.plugin.triggerHistory.class=org.quartz.plugins.history.LoggingTriggerHistoryPlugin

此外,我还添加了QuartzConfiguration

代码语言:javascript
复制
@Configuration
@EnableScheduling
public class QuartzConfiguration {

    public static final String CONTEXT_KEY = "applicationContext";

    @Autowired
    private DataSource dataSource;

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
        scheduler.setApplicationContextSchedulerContextKey("applicationContext");
        scheduler.setConfigLocation(new ClassPathResource("quartz.properties"));
        scheduler.setDataSource(dataSource);
        scheduler.setWaitForJobsToCompleteOnShutdown(true);
        return scheduler;
    }

}

application.properties中,我定义了:

代码语言:javascript
复制
#PostgreSQL
spring.datasource.url=${postgresql.datasource.url}
spring.datasource.username=${postgresql.datasource.username}
spring.datasource.password=${postgresql.datasource.password}

现在,在启动过程中,应用程序会失败,但有以下例外:

代码语言:javascript
复制
Caused by: org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'dataSource': java.sql.SQLException: There is no DataSource named 'dataSource' [See nested exception: java.sql.SQLException: There is no DataSource named 'dataSource']
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.getConnection(JobStoreSupport.java:783)
    at org.quartz.impl.jdbcjobstore.JobStoreTX.getNonManagedTXConnection(JobStoreTX.java:71)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3861)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.recoverJobs(JobStoreSupport.java:839)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.schedulerStarted(JobStoreSupport.java:695)
    ... 45 more
Caused by: java.sql.SQLException: There is no DataSource named 'dataSource'
    at org.quartz.utils.DBConnectionManager.getConnection(DBConnectionManager.java:104)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.getConnection(JobStoreSupport.java:780)
    ... 49 more

我做错了什么,如何向DataSource提供正确的org.quartz.jobStore.dataSource

EN

回答 1

Stack Overflow用户

发布于 2022-05-29 07:46:36

有两种选择:

  1. 创建一个专门创建DataSource的配置bean。

@Bean public DataSource getDataSource() { DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();dataSourceBuilder.url("jdbc:h2:file:C:/temp/test");dataSourceBuilder.username("sa");dataSourceBuilder.password("");返回dataSourceBuilder.build();}

spring.datasource.jndi-name

  1. 您可以交替使用JNDI,使用

see also

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72421676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档