java.lang.InstantiationError: org.quartz.SimpleTrigger

本文解决Spring4.1+Shiro1.2.3+Quartz2.2.1集成时的问题,因默认实现不适用于Quartz2.2.1,提供了一个定制的会话验证调度器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在集成spring4.1+shiro1.2.3+quartz2.2.1是出现此错误,原因是默认的shiro-quartz1.2.3中的实现是针对quartz1.6版本的实现(详细源码请查看QuartzSessionValidationScheduler),在quartz2.2.1中,SimppleTrigger为接口,所以无法实例化。下面的代码是针对2.2.1版本的实现:
import org.apache.shiro.session.mgt.SessionValidationScheduler;
import org.apache.shiro.session.mgt.ValidatingSessionManager;
import org.apache.shiro.session.mgt.quartz.QuartzSessionValidationJob;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerBuilder;
import org.quartz.TriggerKey;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Quartz2SessionValidationScheduler implements
        SessionValidationScheduler {
    public static final long DEFAULT_SESSION_VALIDATION_INTERVAL = 3600000L;
    private static final String JOB_NAME = "SessionValidationJob";
    private static final Logger log = LoggerFactory
            .getLogger(Quartz2SessionValidationScheduler.class);
    private Scheduler scheduler;
    private boolean schedulerImplicitlyCreated = false;

    private boolean enabled = false;
    private ValidatingSessionManager sessionManager;
    private long sessionValidationInterval = 3600000L;

    public Quartz2SessionValidationScheduler() {
    }

    public Quartz2SessionValidationScheduler(
            ValidatingSessionManager sessionManager) {
        this.sessionManager = sessionManager;
    }

    protected Scheduler getScheduler() throws SchedulerException {
        if (this.scheduler == null) {
            this.scheduler = StdSchedulerFactory.getDefaultScheduler();
            this.schedulerImplicitlyCreated = true;
        }
        return this.scheduler;
    }

    public void setScheduler(Scheduler scheduler) {
        this.scheduler = scheduler;
    }

    public void setSessionManager(ValidatingSessionManager sessionManager) {
        this.sessionManager = sessionManager;
    }

    public boolean isEnabled() {
        return this.enabled;
    }

    public void setSessionValidationInterval(long sessionValidationInterval) {
        this.sessionValidationInterval = sessionValidationInterval;
    }

    public void enableSessionValidation() {
        if (log.isDebugEnabled()) {
            log.debug("Scheduling session validation job using Quartz with session validation interval of ["
                    + this.sessionValidationInterval + "]ms...");
        }

        try {
            SimpleTrigger trigger = TriggerBuilder
                    .newTrigger()
                    .startNow()
                    .withIdentity(JOB_NAME, "DEFAULT")
                    .withSchedule(
                            SimpleScheduleBuilder.simpleSchedule()
                                    .withIntervalInMilliseconds(
                                            sessionValidationInterval)).build();

            JobDetail detail = JobBuilder
                    .newJob(QuartzSessionValidationJob.class)
                    .withIdentity(JOB_NAME, "DEFAULT").build();
            detail.getJobDataMap().put("sessionManager", this.sessionManager);
            Scheduler scheduler = getScheduler();

            scheduler.scheduleJob(detail, trigger);
            if (this.schedulerImplicitlyCreated) {
                scheduler.start();
                if (log.isDebugEnabled()) {
                    log.debug("Successfully started implicitly created Quartz Scheduler instance.");
                }
            }
            this.enabled = true;

            if (log.isDebugEnabled())
                log.debug("Session validation job successfully scheduled with Quartz.");
        } catch (SchedulerException e) {
            if (log.isErrorEnabled())
                log.error(
                        "Error starting the Quartz session validation job.  Session validation may not occur.",
                        e);
        }
    }

    public void disableSessionValidation() {
        if (log.isDebugEnabled()) {
            log.debug("Stopping Quartz session validation job...");
        }
        Scheduler scheduler;
        try {
            scheduler = getScheduler();
            if (scheduler == null) {
                if (log.isWarnEnabled()) {
                    log.warn("getScheduler() method returned a null Quartz scheduler, which is unexpected.  Please check your configuration and/or implementation.  Returning quietly since there is no validation job to remove (scheduler does not exist).");
                }

                return;
            }
        } catch (SchedulerException e) {
            if (log.isWarnEnabled()) {
                log.warn(
                        "Unable to acquire Quartz Scheduler.  Ignoring and returning (already stopped?)",
                        e);
            }
            return;
        }
        try {
            scheduler.unscheduleJob(new TriggerKey("SessionValidationJob",
                    "DEFAULT"));
            if (log.isDebugEnabled())
                log.debug("Quartz session validation job stopped successfully.");
        } catch (SchedulerException e) {
            if (log.isDebugEnabled()) {
                log.debug(
                        "Could not cleanly remove SessionValidationJob from Quartz scheduler.  Ignoring and stopping.",
                        e);
            }

        }

        this.enabled = false;

        if (this.schedulerImplicitlyCreated)
            try {
                scheduler.shutdown();
            } catch (SchedulerException e) {
                if (log.isWarnEnabled())
                    log.warn(
                            "Unable to cleanly shutdown implicitly created Quartz Scheduler instance.",
                            e);
            } finally {
                setScheduler(null);
                this.schedulerImplicitlyCreated = false;
            }
    }
}

转自:http://blog.youkuaiyun.com/huangsu2014/article/details/43409577

帮我分析一下springboot报错 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'interceptorConfig': Unsatisfied dependency expressed through field 'sqlSessionFactoryList'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mybatisPlusInterceptor' defined in class path resource [com/baiyue/zhongxiang/config/MybatisPlusConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor]: Factory method 'mybatisPlusInterceptor' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'paginationInnerInterceptor' defined in class path resource [com/baiyue/zhongxiang/config/MybatisPlusConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor]: Factory method 'paginationInnerInterceptor' threw exception; nested exception is java.lang.InstantiationError: net.sf.jsqlparser.statement.select.SelectItem
最新发布
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值