Инъекция в моей работе с кварцем

I would like to know how can I use injection in my job using guice. As I can't use @Inject on the default constructor may I use it directly on the attribute as follow (I always got a NullPointerException with PersonDAO) ? I know that a DAO has nothing to do here but it's just for testing.

public class SimpleQuartzJob implements Job {

  @Inject PersonDao Person;

  private static Logger logger = Logger.getLogger(SimpleQuartzJob.class.getName());

  public SimpleQuartzJob() {
  }

  @Override
  public void execute(JobExecutionContext context) throws JobExecutionException {
    if (logger.isDebugEnabled()) logger.debug("In SimpleQuartzJob - executing its JOB at " 
        + new Date() + " by " + context.getTrigger().getName());

        // ... LOGIC ...
  }

} 

In my module I have the following declaration:

bind(PersonDao.class).to(HibernatePersonDaoImpl.class);

Actually I use the PersonDao here 'cause I know it works within another class with injection (but the injection is done on the constructor level there).

Can someone give me an advice?

Here is more info about quartz config:

Web.xml:

  <servlet>  
    <servlet-name>QuartzInitializer</servlet-name>  
    <display-name>Quartz Initializer Servlet</display-name>  
    <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>  
    <load-on-startup>1</load-on-startup>  
    <init-param>  
        <param-name>config-file</param-name>  
        <param-value>/quartz.properties</param-value>  
    </init-param>  
    <init-param>  
        <param-name>shutdown-on-unload</param-name>  
        <param-value>true</param-value>  
    </init-param>  
    <init-param>  
        <param-name>start-scheduler-on-load</param-name>  
        <param-value>true</param-value>  
    </init-param>  
</servlet>

quartz.properties:

org.quartz.plugin.jobInitializer.class=org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames=quartz-config.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 5
org.quartz.threadPool.threadPriority = 5

quartz-config.xml :

<?xml version='1.0' encoding='utf-8'?>
<job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
  version="1.8">

    <schedule>
        <job>
            <name>mail-job</name>
            <group>MYJOB_GROUP</group>

            <description>The job description</description>
            <job-class>svc.data.server.quartz.SimpleQuartzJob</job-class>
        </job>

        <trigger>
            <cron>
                <name>my-trigger</name>
                <group>MYTRIGGER_GROUP</group>
                <job-name>mail-job</job-name>

                <job-group>MYJOB_GROUP</job-group>
                <cron-expression>10 * * * * ?</cron-expression>

            </cron>
        </trigger>
    </schedule>
</job-scheduling-data>
10
задан ROMANIA_engineer 24 August 2017 в 21:02
поделиться