tomcat8 - Using Quartz2 and Bean CDI -
i need create method executes automatically whenever tomcat starts. followed tutorial , implement method implements org.quartz.job, it's working, problem not let me inject bean cdi in method, stop running without log errors.
i found out quartz must integrated use cdi, i've tried deltaspike , gives me errors, have idea?
i use:
- jsf 2.2
- cdi
- tomcat 8
- eclipse ide
- maven
my job class:
package com.sisrastrbov.schedule; import org.quartz.job; import org.quartz.jobexecutioncontext; import org.quartz.jobexecutionexception; public class schedulerjob implements job { @override public void execute(jobexecutioncontext context) throws jobexecutionexception { system.out.println("jsf 2 + quartz 2 example"); } }
my pom.xml dependencies:
<dependencies> <dependency> <groupid>org.primefaces.themes</groupid> <artifactid>bootstrap</artifactid> <version>1.0.10</version> <scope>compile</scope> </dependency> <!-- núcleo hibernate --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>5.1.0.final</version> <scope>compile</scope> </dependency> <dependency> <groupid>totalsat</groupid> <artifactid>totalsat</artifactid> <version>1.0</version> </dependency> <!-- implementação hibernate beanvalidator --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-validator</artifactid> <version>5.1.3.final</version> <scope>compile</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.axis/axis --> <dependency> <groupid>org.apache.axis</groupid> <artifactid>axis</artifactid> <version>1.4</version> </dependency> <!-- https://mvnrepository.com/artifact/org.jboss.spec.javax.xml.rpc/jboss-jaxrpc-api_1.1_spec --> <dependency> <groupid>org.jboss.spec.javax.xml.rpc</groupid> <artifactid>jboss-jaxrpc-api_1.1_spec</artifactid> <version>1.0.1.final</version> </dependency> <!-- https://mvnrepository.com/artifact/xerces/xercesimpl --> <!-- implementação entitymanager da jpa --> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-entitymanager</artifactid> <version>5.1.0.final</version> <scope>compile</scope> </dependency> <dependency> <groupid>wsdl4j</groupid> <artifactid>wsdl4j</artifactid> <version>1.6.2</version> </dependency> <!-- https://mvnrepository.com/artifact/org.jboss.weld.servlet/weld-servlet --> <dependency> <groupid>org.jboss.weld.servlet</groupid> <artifactid>weld-servlet</artifactid> <version>2.3.1.final</version> </dependency> <dependency> <groupid>org.jboss</groupid> <artifactid>jandex</artifactid> <version>1.2.2.final</version> <scope>compile</scope> </dependency> <dependency> <groupid>postgresql</groupid> <artifactid>postgresql</artifactid> <version>9.1-901-1.jdbc4</version> <scope>compile</scope> </dependency> <!-- mojarra (implementação jsf 2) --> <dependency> <groupid>org.glassfish</groupid> <artifactid>javax.faces</artifactid> <version>2.2.9</version> <scope>compile</scope> </dependency> <!-- omnifaces --> <dependency> <groupid>org.omnifaces</groupid> <artifactid>omnifaces</artifactid> <version>1.5</version> <scope>compile</scope> </dependency> <!-- primefaces biblioteca de componentes --> <dependency> <groupid>org.primefaces</groupid> <artifactid>primefaces</artifactid> <version>5.3</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web --> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-web</artifactid> <version>3.1.4.release</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config --> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-config</artifactid> <version>3.1.4.release</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core --> <dependency> <groupid>org.springframework.security</groupid> <artifactid>spring-security-core</artifactid> <version>3.1.4.release</version> </dependency> <dependency> <groupid>commons-logging</groupid> <artifactid>commons-logging</artifactid> <version>1.1.3</version> <scope>compile</scope> </dependency> <dependency> <groupid>org.apache.commons</groupid> <artifactid>commons-lang3</artifactid> <version>3.1</version> <scope>compile</scope> </dependency> <!-- api de servlet --> <dependency> <groupid>javax.servlet</groupid> <artifactid>javax.servlet-api</artifactid> <version>3.1.0</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/javax.mail/mail --> <dependency> <groupid>javax.mail</groupid> <artifactid>mail</artifactid> <version>1.4</version> </dependency> <!-- listener --> <!-- jsf 2 libraries --> <dependency> <groupid>com.sun.faces</groupid> <artifactid>jsf-api</artifactid> <version>2.1.11</version> </dependency> <dependency> <groupid>com.sun.faces</groupid> <artifactid>jsf-impl</artifactid> <version>2.1.11</version> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>servlet-api</artifactid> <version>2.5</version> </dependency> <dependency> <groupid>javax.servlet.jsp</groupid> <artifactid>jsp-api</artifactid> <version>2.1</version> </dependency> <!-- tomcat 6 need --> <dependency> <groupid>com.sun.el</groupid> <artifactid>el-ri</artifactid> <version>1.0</version> </dependency> <!-- quartz scheduler framework --> <dependency> <groupid>org.quartz-scheduler</groupid> <artifactid>quartz</artifactid> <version>2.1.5</version> </dependency> <!-- quartz need transaction --> <dependency> <groupid>javax.transaction</groupid> <artifactid>jta</artifactid> <version>1.1</version> </dependency> </dependencies>
web.xml:
<?xml version="1.0" encoding="utf-8" ?> <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> <context-param> <param-name>primefaces.font_awesome</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>contextconfiglocation</param-name> <param-value> /web-inf/applicationcontext.xml </param-value> </context-param> <session-config> <session-timeout>-1</session-timeout> </session-config> <listener> <listener-class> org.quartz.ee.servlet.quartzinitializerlistener </listener-class> </listener> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.requestcontextlistener</listener-class> </listener> <listener> <listener-class>org.springframework.security.web.session.httpsessioneventpublisher</listener-class> </listener> <listener> <listener-class>org.jboss.weld.environment.servlet.listener</listener-class> </listener> <resource-env-ref> <resource-env-ref-name>beanmanager</resource-env-ref-name> <resource-env-ref-type> javax.enterprise.inject.spi.beanmanager </resource-env-ref-type> </resource-env-ref> <welcome-file-list> <welcome-file>main.xhtml</welcome-file> </welcome-file-list> <servlet> <servlet-name>faces servlet</servlet-name> <servlet-class>javax.faces.webapp.facesservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>faces servlet</servlet-name> <url-pattern>*.xhtml</url-pattern> </servlet-mapping> <mime-mapping> <extension>woff</extension> <mime-type>application/font-woff</mime-type> </mime-mapping> <mime-mapping> <extension>woff2</extension> <mime-type>application/font-woff2</mime-type> </mime-mapping> <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> <dispatcher>forward</dispatcher> <dispatcher>request</dispatcher> </filter-mapping> </web-app>
wow, coud have add spingframework :) should job:
@javax.ejb.singleton @javax.ejb.startup public class startup { @postconstruct public void start() { system.out.println("start"); } }
pom.xml
<dependency> <groupid>javax</groupid> <artifactid>javaee-api</artifactid> <version>7.0</version> <scope>provided</scope> </dependency>
keep simple :) should think replacing quartz jee scheduler if use case matches http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html
Comments
Post a Comment