使用SimpleTriggerFactoryBean

时间:2016-09-21 16:09:52

标签: java spring quartz-scheduler

我正在尝试将项目从spring 2.5.6和java 6迁移到spring 4.2和java 8,在wildfly 9服务器上运行。我根据讨论和示例更新了SimpleTriggerBean对SimpleTriggerFactoryBean的引用(例如http://websystique.com/spring/spring-4-quartz-scheduler-integration-example/

但是,当我运行应用程序时,我收到以下错误;

  

WARN [org.springframework.web.context.support.XmlWebApplicationContext](ServerService线程池 - 66)上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.BeanCreationException:使用名称创建bean时出错' invalSvc'在ServletContext资源中定义[/WEB-INF/classes/resources/spring/spring-cfg.xml]:无法解析对bean的引用' changeHelper'设置bean属性' changeHelper&#39 ;;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为' changeHelper'的bean时出错在ServletContext资源[/WEB-INF/classes/resources/spring/spring-cfg.xml]中定义:无法解析对bean的引用' invalRpcHelper'设置bean属性' invalRpcHelper&#39 ;;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为' invalRpcHelper'的bean时出错。在ServletContext资源中定义[/WEB-INF/classes/resources/spring/spring-cfg.xml]:bean的初始化失败;嵌套异常是java.lang.NoClassDefFoundError:org / springframework / scheduling / quartz / SimpleTriggerBean

我正在运行的代码没有任何对SimpeTriggerBean的可视化引用,我无法弄清楚为什么会发生这种情况。 SimpleTriggerFactoryBean应该在Quartz 1.x和2.x中都有效。

Spring xml数据;

<bean name="retryHandlerImpl" class="com.myproject.code.rpc.vscall.RetryHandlerImpl">
    <property name="passwordManager" ref="passwordManager" />
    <property name="signal" ref="signal" /> 
    <property name="handleToSTB" ref="fileTrigger" />  
    <property name="serverLoader" ref="serverLoader" />
    <property name="serializeHelper" ref="serializeHelper" /> 
</bean>

<bean name="invalRpcHelper" class="com.myproject.code.rpc.calls.InvalRpcHelperImpl">
    <property name="rpcHelper" ref="retryHandlerImpl" />
</bean>

<bean name="inputController"
    class="com.myproject.code.control.InputController">
        <property name="partnerDao" ref="partnerDao" />
        <property name="passwordManager" ref="passwordManager" />
        <property name="appData" ref="appData" />
        <property name="signal" ref="signal" />
        <property name="fileHelper" ref="fileHelper" />
</bean>


    <!--  Non Quartz Job Scheduling -->
<bean id="scheduleFileReaderJob"
    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="inputController"/>
    <property name="targetMethod" value="startFrontEndProcesses" >

    </property>

    <!--  dont want two instances of reader bean to run -->
    <property name="concurrent" value="false" />
</bean>

<bean id="fileTrigger"
    class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
    <property name="jobDetail" ref="scheduleFileReaderJob" />
    <property name="startDelay" value="0" />
    <property name="repeatInterval" value="${FILE_POLL_INTERVAL}" />
</bean>

RetryHandlerImpl的相关剪切;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

import org.apache.log4j.Logger;
/* upgrading from spring 2.5.4 */
//import org.springframework.scheduling.quartz.SimpleTriggerBean;
/* to */
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;

// -> a lot of project class imports go here

public class RetryHandlerImpl extends RpcHelperImpl {

    private static PasswordManager passwordManager;

    private static Signal signal;

    private static SimpleTriggerFactoryBean handleToSTB;

    private static ServerLoader serverLoader;

    private static SerializeHelper serializeHelper;

    private static Logger log = Logger.getLogger(RetryHandlerImpl.class
            .getName());

    private static int noOfRetries = 0;

    private static final int MAX_RETRIES;

    private static final int HIBERNATE_TIME_IN_MINUTES;

    static {
        try {
            MAX_RETRIES = Integer.parseInt(VMProps.get(CommonCons.MAX_RETRIES));
            HIBERNATE_TIME_IN_MINUTES = Integer.parseInt(VMProps
                    .get(VMCons.HIBERNATE_TIME_IN_MINUTES));
        } catch (Exception ignore) {
            throw new AppException(CommonCons.APP_INIT_ERROR);
        }
    }

    /**
     * This code sets the application to hibernate.
     * 
     * The second argument:
     * 
     * If it is true, it means that the same server must be used for processing
     * as already a call has gone to this server
     * 
     * If it is false, then it starts trying from the first server in the list
     * of serverLoader.servers
     * 
     */
    private void setAppToHibernateMode(boolean callNotPlaced,
            Server currentServer) {

        makeItEasyForUsByLogging(log, callNotPlaced, currentServer);

        // Select the hibernate time
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MINUTE, HIBERNATE_TIME_IN_MINUTES);
        Date date = c.getTime();
        handleToSTB.setStartTime(date);

        if (callNotPlaced) {
            log.info("Since callNotPlaced is " + callNotPlaced
                    + " setting currentServer to null ");
            signal.setCurrentServer(null);
        }

        serializeHelper.serializeSignal(signal);

        // There shall be no more retries,
        // while loop shall exit automatically,
        // Instead we throw the error.
        throw new VSException(ErrCons.APP_HIBERNATE);

    }

    public void setSignal(Signal sig) {
        signal = sig;
    }

    public void setHandleToSTB(SimpleTriggerFactoryBean handleToST) {
        this.handleToSTB = handleToST;
    }

    @Override
    public void setServerLoader(ServerLoader serverLoad) {
        this.serverLoader = serverLoad;
    }

    public void setSerializeHelper(SerializeHelper serializeHelper) {
        this.serializeHelper = serializeHelper;
    }

    private void logboth(String message) {
        log.error(message);
        Metrics.writeln(message);
    }
}

POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                             http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- Spring version utility -->
    <spring.version>4.3.2.RELEASE</spring.version>
    <spring-ws.version>2.2.4.RELEASE</spring-ws.version>    

</properties>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>                
            </plugin>
        </plugins>      
    </pluginManagement> 
</build>

<dependencies>
    <!-- I have tested with multiple versions of quartz and without it, but to no avail.
    <dependency>
        <groupId>quartz</groupId>
        <artifactId>quartz</artifactId>
        <version>1.5.2</version>
    </dependency>

    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>1.8.5</version>
    </dependency>

    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>2.2.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.archiva.redback.components</groupId>
        <artifactId>spring-quartz</artifactId>
        <version>2.0</version>
    </dependency>

    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz-jobs</artifactId>
        <version>2.0.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.servicemix.bundles</groupId>
        <artifactId>org.apache.servicemix.bundles.spring-context-support</artifactId>
        <version>4.0.1.RELEASE_4</version>
    </dependency>
    -->

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.4</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>  
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk16</artifactId>
        <version>1.46</version>
    </dependency>

    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcpg-jdk16</artifactId>
        <version>1.46</version>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>

    <dependency>
        <groupId>toplink.essentials</groupId>
        <artifactId>toplink-essentials</artifactId>
        <version>2.1-60f</version>
    </dependency>

    <dependency>
        <groupId>org.easymock</groupId>
        <artifactId>easymock</artifactId>
        <version>2.4</version>
    </dependency>

    <dependency>
        <groupId>com.jcraft</groupId>
        <artifactId>jsch</artifactId>
        <version>0.1.53</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.4</version>
    </dependency>

    <dependency>
        <groupId>commons-httpclient</groupId>
        <artifactId>commons-httpclient</artifactId>
        <version>3.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.4.1</version>
    </dependency>

    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.9.2</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.xmlrpc</groupId>
        <artifactId>xmlrpc-client</artifactId>
        <version>3.1.3</version>
    </dependency>

    <dependency>
        <groupId>org.apache.xmlrpc</groupId>
        <artifactId>xmlrpc-common</artifactId>
        <version>3.1.3</version>
    </dependency>

    <dependency>
        <groupId>org.apache.ws.commons.util</groupId>
        <artifactId>ws-commons-util</artifactId>
        <version>1.0.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.xmlrpc</groupId>
        <artifactId>xmlrpc-server</artifactId>
        <version>3.1.3</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>4.1.3.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core</artifactId>
        <version>${spring-ws.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core-tiger</artifactId>
        <version>1.5.10</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-security</artifactId>
        <version>${spring-ws.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-support</artifactId>
        <version>${spring-ws.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-xml</artifactId>
        <version>${spring-ws.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
      <groupId>com.googlecode.ehcache-spring-annotations</groupId>
      <artifactId>ehcache-spring-annotations</artifactId>
      <version>1.2.0</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.castor</groupId>
        <artifactId>castor</artifactId>
        <version>1.2</version>
        <!-- <scope>provided</scope> -->
    </dependency>

    <dependency>
        <groupId>logkit</groupId>
        <artifactId>logkit</artifactId>
        <version>1.0.1</version>
        <!-- <scope>provided</scope> -->
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa</artifactId>
        <version>2.6.4</version>
    </dependency>

    <dependency>
        <groupId>org.jdom</groupId>
        <artifactId>jdom</artifactId>
        <version>1.1.3</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>

</dependencies>  
</project>

我已经测试了弹簧和石英的多个版本。

如果我从retryHandlerImpl中删除所有引用(包括inputController,scheduleFileReaderJob和fileTrigger),则仍会抛出异常。

<bean name="retryHandlerImpl" class="com.myproject.code.rpc.vscall.RetryHandlerImpl">
/*
    <property name="passwordManager" ref="passwordManager" />
    <property name="signal" ref="signal" /> 
    <property name="handleToSTB" ref="fileTrigger" />  
    <property name="serverLoader" ref="serverLoader" />
    <property name="serializeHelper" ref="serializeHelper" /> 
*/
</bean>

<bean name="invalRpcHelper" class="com.myproject.code.rpc.calls.InvalRpcHelperImpl">
    //<property name="rpcHelper" ref="retryHandlerImpl" />
</bean>

任何关于为什么存在这种依赖关系的想法或想法,或者哪个版本的库将是神奇的组合,都是最受欢迎的。

致以最诚挚的问候,

1 个答案:

答案 0 :(得分:1)

<强>解决方案:  在从ant升级到maven的过程中,出现了一个错误,并且编译版本的类放在WEB-INF目录中。

这导致运行时出现一些离散的冲突。只有不加载所涉及的类才会让应用程序绕过问题,从而导致可疑症状。

从WEB-INF中删除文件夹解决了这个问题。