带有Quartz和Tomcat数据源的SpringBoot:驱动程序的Blob表示形式是不受支持的类型:oracle.sql.BLOB

时间:2017-04-10 10:36:11

标签: spring tomcat datasource quartz

我正在使用SpringBoot 1.4.5和quartz进行调度,并在Tomcat的context.xml中配置了一个DataSource,它通过JndiDataSource注入bean,用于连接到Oracle 10g DB。

以下是相关的依赖项,包括Oracle驱动程序,我正在使用SpringBoot提供的依赖项管理:

# views.py
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import ModelFormWithFileField

def upload_file(request):
    if request.method == 'POST':
        form = ModelFormWithFileField(request.POST, request.FILES)
        if form.is_valid():
            # file is saved
            form.save()
            return HttpResponseRedirect('/success/url/')
    else:
        form = ModelFormWithFileField()
    return render(request, 'upload.html', {'form': form})

这是在context.xml中在Tomcat中配置的DataSource(占位符属性在catalina.properties中定义):

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz-jobs</artifactId>
            <version>2.2.1</version>
        </dependency>
            <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>oracle-ojdbc7</artifactId>
            <version>12.1.0-2</version>
        </dependency>

数据源bean配置和石英必需的bean:

<Resource name="${tomcat.dbpool.ups.quartz.resourcename}" auth="Container"
                type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
                url="${tomcat.dbpool.ups.quartz.connectionurl}"
                username="${tomcat.dbpool.ups.quartz.username}"
                password="${tomcat.dbpool.ups.quartz.password}"
                maxTotal="${tomcat.dbpool.ups.quartz.maxTotal}"
                maxIdle="${tomcat.dbpool.ups.quartz.maxIdle}"
                minIdle="${tomcat.dbpool.ups.quartz.minIdle}"
                maxWaitMillis="${tomcat.dbpool.ups.quartz.maxWaitMillis}"
                validationQueryTimeout="${tomcat.dbpool.ups.quartz.validationQueryTimeout}"
                testWhileIdle="true"
                removeAbandonedOnMaintenance="true"
                timeBetweenEvictionRunsMillis="${tomcat.dbpool.ups.quartz.timeBetweenEvictionRunsMillis}"
                minEvictableIdleTimeMillis="${tomcat.dbpool.ups.quartz.minEvictableIdleTimeMillis}"
                />

以及quartz.properties文件中的以下属性:

@Bean
    public JobFactory jobFactory(final ApplicationContext applicationContext) {
        final AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
        jobFactory.setApplicationContext(applicationContext);
        return jobFactory;
    }

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean(@Qualifier("quartzDataSource") final DataSource quartzDS,
                                                     final JobFactory jobFactory,
                                                     @Qualifier("loansAppTrigger") final Trigger jobTrigger) throws IOException {
        final SchedulerFactoryBean factory = new SchedulerFactoryBean();
        // this allows to update triggers in DB when updating settings in config file:
        factory.setOverwriteExistingJobs(true);
        factory.setDataSource(quartzDS);
        factory.setJobFactory(jobFactory);

        factory.setQuartzProperties(quartzProperties());
        factory.setTriggers(jobTrigger);

        return factory;
    }

    @Bean(name = "quartzDataSource")
    @Profile("!local")
    public DataSource jndiDataSource() {
        JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
        DataSource dataSource = dataSourceLookup.getDataSource("java:comp/env/jdbc/QUARTZ");
        return dataSource;
    }

    @Bean
    public Properties quartzProperties() throws IOException {
        final PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
        propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
        propertiesFactoryBean.afterPropertiesSet();
        return propertiesFactoryBean.getObject();
    }

    @Bean
    public JobDetailFactoryBean checkUnconfirmedApplicationsJobDetail() {
        return createJobDetail(CheckUnconfirmedApplicationsJob.class);
    }

    @Bean(name = "loansAppTrigger")
    public SimpleTriggerFactoryBean unconfirmedLoansApplicationsTrigger(
            @Qualifier("checkUnconfirmedApplicationsJobDetail") final JobDetail jobDetail,
            @Value("${ups.loan.check.pending.apps.frequency}") final long frequency) {
        return createTrigger(jobDetail, frequency);
    }

    private static JobDetailFactoryBean createJobDetail(final Class jobClass) {
        final JobDetailFactoryBean factoryBean = new JobDetailFactoryBean();
        factoryBean.setJobClass(jobClass);
        // job has to be durable to be stored in DB:
        factoryBean.setDurability(true);
        return factoryBean;
    }

    private static SimpleTriggerFactoryBean createTrigger(final JobDetail jobDetail, final long pollFrequencyMs) {
        final SimpleTriggerFactoryBean factoryBean = new SimpleTriggerFactoryBean();
        factoryBean.setJobDetail(jobDetail);
        factoryBean.setStartDelay(0L);
        factoryBean.setRepeatInterval(pollFrequencyMs);
        factoryBean.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
        // in case of misfire, ignore all missed triggers and continue :
        factoryBean.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT);

        return factoryBean;
    }

当我在Tomcat 8上部署它时,我收到以下错误:

org.quartz.JobPersistenceException:无法存储作业:驱动程序的Blob表示形式为usupported类型:oracle.sql.BLOB

在Tomcat的lib文件夹中,我有oracle-ojdbc7-12.1.0-2.jar驱动程序。

1 个答案:

答案 0 :(得分:2)

请检查您是否有任何重复的oracle-ojdbc JAR文件? JAR应该只在一个位置:WEB-INF / lib或tomcat / lib