2016-09-03 9 views
0

それはなぜ観測を知りたいのですか?executeInternal()customerRepositoryの参照を無効にした理由を知りたいのですが?私は開発中でした春+石英+春データJPA例。この例では、JobDetailFactoryBeanの実装を提供することによって複数のジョブを同時に実行することを検討していました。 jobA.javaクラスでは、私は問題....私はexecuteInternal()理由でcustomerRepositoryインスタンスを使用することはできませんorg.quartz-scheduler executeInternal(JobExecutionContext executionContext)のリポジトリの参照を無効にする理由は何ですか?

JobA.java

@Service 
public class JobA extends QuartzJobBean { 

    private CustomerRepository customerRepository = null; 

    @Autowired 
    public JobA(CustomerRepository customerRepository) { 
     this.customerRepository = customerRepository; 
    } 
    public JobA() { } 

    @Override 
    protected void executeInternal(JobExecutionContext executionContext) throws JobExecutionException { 
     System.out.println("~~~~~~~ Job A is runing ~~~~~~~~"); 
     Trigger trigger = executionContext.getTrigger(); 
     System.out.println(trigger.getPreviousFireTime()); 
     System.out.println(trigger.getNextFireTime()); 
     getCustomerList(); 
    } 

    private List<Customer> getCustomerList(){ 
     List<Customer> customers = customerRepository.findAll(); 
     for (Customer customer : customers) { 
      System.out.println("------------------------------"); 
      System.out.println("ID : "+customer.getId()); 
      System.out.println("NAME : "+customer.getName()); 
      System.out.println("STATUS : "+customer.getStatus()); 
     } 
     return customers; 
    } 
} 

を体験しますか?もし私がgetCustomerList()から公衆JobA(CustomerRepository customerRepository) {それはうまく動作しますが、私はexecuteInternal()から使用すると、それはcustomerRepositoryの参照を無効にする理由は?

春Quartz.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" 
    xmlns:repository="http://www.springframework.org/schema/data/repository" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 
     http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd"> 

    <import resource="classpath:dataSourceContext.xml"/> 

    <jpa:repositories base-package="com.mkyong.repository" /> 
    <context:component-scan base-package="com.mkyong.*" /> 
    <context:annotation-config /> 

    <bean id="jobA" class="com.mkyong.job.JobA" /> 
    <bean id="jobB" class="com.mkyong.job.JobB" /> 
    <bean id="jobC" class="com.mkyong.job.JobC" /> 

    <!-- ~~~~~~~~~ Quartz Job ~~~~~~~~~~ --> 
    <bean name="JobA" class="org.springframework.scheduling.quartz.JobDetailFactoryBean"> 
     <property name="jobClass" value="com.mkyong.job.JobA" /> 
    </bean> 

    <bean name="JobB" class="org.springframework.scheduling.quartz.JobDetailFactoryBean"> 
     <property name="jobClass" value="com.mkyong.job.JobB" /> 
    </bean> 

    <bean name="JobC" class="org.springframework.scheduling.quartz.JobDetailFactoryBean"> 
     <property name="jobClass" value="com.mkyong.job.JobC" /> 
    </bean> 

    <!-- ~~~~~~~~~~~ Cron Trigger, run every 5 seconds ~~~~~~~~~~~~~ --> 
    <bean id="cronTriggerJobA" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 
     <property name="jobDetail" ref="JobA" /> 
     <property name="cronExpression" value="0/5 * * * * ?" /> 
    </bean> 

    <bean id="cronTriggerJobB" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 
     <property name="jobDetail" ref="JobB" /> 
     <property name="cronExpression" value="0/5 * * * * ?" /> 
    </bean> 

    <bean id="cronTriggerJobC" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 
     <property name="jobDetail" ref="JobC" /> 
     <property name="cronExpression" value="0/5 * * * * ?" /> 
    </bean> 

    <!-- ~~~~~~~~~~~~~~~~ Scheduler bean Factory ~~~~~~~~~~~~~~~~ --> 
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
     <property name="triggers"> 
      <list> 
       <ref bean="cronTriggerJobA" /> 
       <!-- <ref bean="cronTriggerJobB" /> 
       <ref bean="cronTriggerJobC" /> --> 
      </list> 
     </property> 
    </bean> 
</beans> 

dataSourceContext.xml

<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd 
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> 

    <context:property-placeholder location="classpath:database.properties"/> 

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"/> 


    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="${mysql.driver.class.name}" /> 
     <property name="url" value="${mysql.url}" /> 
     <property name="username" value="${mysql.username}" /> 
     <property name="password" value="${mysql.password}" /> 
    </bean> 

    <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
     <property name="showSql" value="true"/> 
     <property name="generateDdl" value="true"/> 
     <property name="database" value="${database.vendor}"/> 
    </bean> 

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
     <property name="dataSource" ref="dataSource"/> 

     <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/> 

     <!-- spring based scanning for entity classes--> 
     <property name="packagesToScan" value="com.mkyong.*"/> 
    </bean> 
</beans> 

App.java

public class App { 
    public static void main(String[] args) throws Exception { 
     ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Quartz.xml"); 
    } 
} 

答えて

0

あなたはcustomerRepository beanを定義していますか? xmlファイルに定義するか、クラスに@Repository annonationを追加する必要があります。

関連する問題