I have Quartz 2.2.1 and Spring 3.2.8 app. My problem is that during startup Quartz creates two jobs with the following one 2 seconds later. My job must be executed every 10 seconds, yet it executes twice:
Info: INFO: Starting TASK on Mon Apr 20 16:22:21 CEST 2015
Info: INFO: Starting TASK on Mon Apr 20 16:22:23 CEST 2015
Info: INFO: Starting TASK on Mon Apr 20 16:22:31 CEST 2015
Info: INFO: Starting TASK on Mon Apr 20 16:22:33 CEST 2015
Info: INFO: Starting TASK on Mon Apr 20 16:22:41 CEST 2015
Info: INFO: Starting TASK on Mon Apr 20 16:22:43 CEST 2015
I tried to follow the suggestions on Quartz + Spring double execution on startup. The provided answers (removal of tag containing "ContextLoaderListener" within web.xml) didn't help as I had an error that the WebContext was missing. Thanks for your help.
Here is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://ift.tt/nSRXKP"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/nSRXKP
http://ift.tt/LU8AHS">
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<jsp-property-group>
<description>header and footer settings</description>
<url-pattern>/WEB-INF/*</url-pattern>
<include-prelude>/WEB-INF/header.jspf</include-prelude>
</jsp-property-group>
</jsp-config>
<!-- Spring Security -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>utils.SessionCounterListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-servlet.xml
</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
My spring-servlet.xml look like this:
<?xml version="1.0" encoding="windows-1252"?> <beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:p="http://ift.tt/1jdM0fE"
xmlns:context="http://ift.tt/GArMu7"
xmlns:mvc="http://ift.tt/1bHqwjR"
xmlns:aop="http://ift.tt/OpNdV1"
xmlns:tx="http://ift.tt/OGfeU2"
xsi:schemaLocation="
http://ift.tt/GArMu6
http://ift.tt/QEDs1e
http://ift.tt/GArMu7
http://ift.tt/QEDs1k
http://ift.tt/1bHqwjR
http://ift.tt/1bVJL9q
http://ift.tt/OpNdV1
http://ift.tt/QEDs1g
http://ift.tt/OGfeU2
http://ift.tt/1cQrvTl">
<!-- Use @Component annotations for bean definitions -->
<context:component-scan base-package="cinema"/>
<!-- Use @Controller annotations for MVC controller definitions -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
<bean id="exampleBusinessObject" class="cinema.controller.ServerMonitorController"/>
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="exampleBusinessObject"/>
<property name="targetMethod" value="sendIt"/>
<property name="concurrent" value="false"/>
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail"/>
<!-- czas do odczekania
<property name="startDelay" value="10000"/>-->
<!-- czas pomiedzy odpaleniami (50 sek = 50000) -->
<property name="repeatInterval" value="10000"/>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="simpleTrigger"/>
</list>
</property>
</bean>
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.glassfish.GlassFishLoadTimeWeaver"/>
</property>
</bean>
<tx:jta-transaction-manager />
<!-- Use @Transaction annotations for managing transactions -->
<tx:annotation-driven />
<!-- View resolver -->
<bean class=
"org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
</bean>
<import resource="/spring-security.xml" /> </beans>
ServerMonitorController.java :
@Controller
public class ServerMonitorController {
public static void sendIt() throws FileNotFoundException, IOException {
System.out.println("INFO: Starting TASK on "+ new Date());
}
}
Aucun commentaire:
Enregistrer un commentaire