Spring XD - 不适用于context:annotation-config

时间:2016-10-18 03:40:09

标签: java spring spring-data-jpa spring-xd

我定义了一个Spring XD BatchJob,它通过Spring JPA与DB交互。 问题是:Spring XD无法自动实例化由JavaConfig配置的Bean,并在创建作业定义

时出现异常

我的Bean代码是:

@Service("messageDomainService")
public class MessageDomainService {

    private MessageRepository messageRepository;

    @Autowired
    public MessageDomainService(MessageRepository messageRepository) {
        this.messageRepository = messageRepository;
    }

    public void save(Message simpleTweet) {
        messageRepository.save(simpleTweet);
    }
}
public class CustomerTasklet implements Tasklet{

    @Autowired
    private MessageDomainService messageDomainService;

    public CustomerTasklet() {
        super();
    }

    public RepeatStatus execute(StepContribution contribution,
            ChunkContext chunkContext) throws Exception {
        messageDomainService.save(new Message("TEXT"));
        return RepeatStatus.FINISHED;
    }

    public MessageDomainService getJdbcCustomerDao() {
        return messageDomainService;
    }

    public void setJdbcCustomerDao(MessageDomainService messageDomainService) {
        this.messageDomainService = messageDomainService;
    }
}

xml at:src/main/resources/config

   <context:annotation-config/>

    <batch:job id="job">
        <batch:step id="step1">
            <batch:tasklet ref="customerTasklet" />
        </batch:step>
    </batch:job>

    <bean id="customerTasklet" class="xxx.CustomerTasklet">
        <property name="messageDomainService" ref="messageDomainService" />
    </bean>

例外:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.xd.moduleoption.postgresql.MessageDomainService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
    ... 47 more
}

我也使用:

@Configuration
@Import(HibernateJpaAutoConfiguration.class)
@EnableJpaRepositories("xxx")
@EntityScan("xxx")
public class BeanConfig {
    @Autowired
    MessageDomainService messageDomainService;  
}

并配置: 的 spring-module.properties:

base_packages=xxx

谢谢&amp;问候, Loi Le

0 个答案:

没有答案