如何从Quartz作业中获取参考ServletContext?

时间:2015-10-10 15:52:29

标签: java eclipse java-ee quartz-scheduler web-application-project

我想从Quartz作业中获取一个参考ServletContext来访问WEB-INF文件夹中我自己的Web应用程序属性的文件,但我是Quartz Scheduler的新手,我不能。

该文件位于:/ WEB-INF/mypreferences.properties,并希望从Quartz作业中读取。

我正在使用Eclipse Java EE和Quartz Scheduler 2.2.1。

我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>My Web Application</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>QuartzInitializer</servlet-name>
        <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
        <init-param>
            <param-name>shutdown-on-unload</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <context-param>
        <param-name>quartz:config-file</param-name>
        <param-value>quartz.properties</param-value>
    </context-param>
</web-app>

我的工作石英:

public class MyJob implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //Get ServletContext reference and read the properties file my own web application
    }
}

0 个答案:

没有答案