2017-04-18 34 views
0

我有一個QuartzJobBean石英自動連接字段爲空

public abstract class SqsQueueListener extends QuartzJobBean { 

    @Value("test-queue") 
    private String queueName; 

    @Autowired 
    private AmazonSQS sqsClient; 

    @Override 
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException { 
     LOGGER.info("Attempt to get message for SQS queue for client: [{}].", sqsClient); 
     GetQueueUrlResult result = sqsClient.getQueueUrl(queueName); 
    } 

    protected abstract void notificationAction(String message); 

} 

我有它的擴展該類但沒有什麼特別有非抽象實現。 預計到autowire sqsClient。

SqsClient使用FactoryBean

<bean id="sqsClient" class="pack.SqsClientFactoryBean"/> 

在日誌中它顯示我消息對象已成功創建這樣的工廠本身創作的作品。

xml配置看起來像這樣

<bean id="sqsProcessingJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean"> 
    <property name="jobClass" value="pack.RuleReloadingSqsService"/> 
    <property name="jobDataAsMap"> 
     <map> 
      <entry key="sqsClient" value="sqsClient"/> 
     </map> 
    </property> 
</bean> 

<bean id="sqsTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean"> 
    <property name="jobDetail" ref="sqsProcessingJob"/> 
    <property name="repeatInterval" value="10000"/> 
</bean> 

<bean class="pack.quartz.DisablingSchedulerFactoryBean"> 
    <property name="triggers"> 
     <list> 
      <ref bean="sqsTrigger"/> 
     </list> 
    </property> 
</bean> 

然而,當我跑我的應用程序得到sqsClientnull。問題是什麼?

回答

0

我忘了給sqsClient添加setter。

private AmazonSQS sqsClient; 

@Override 
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {} 

public void setSqsClient(AmazonSQS sqsClient) { 
    this.sqsClient = sqsClient; 
}