Spring集成,自动接线失败(null)

时间:2015-05-22 15:28:25

标签: spring spring-integration autowired

我正在使用spring集成来收听电子邮件。

我有一个名为mailService的Spring组件,它被实例化,每次新邮件到达时都会调用processedMail方法。

我想在EmailService中添加更多代码,如下所示:

@Component(value="mailService")
public class EmailService {

@Autowired
private ApplicationContext applicationContext;

我的问题是访问applicationContext时有一个空指针异常

你知道这可以来自哪里吗?我的applicationContext.xml文件已被读取。所有通道都已启动,并且mallService组件已由Spring实例化。我应该在配置中添加特定内容吗?

更多代码:

@Component(value="mailService")
public class EmailService {

    private final static Logger logger =  Logger.getLogger(EmailService.class);
    @Autowired
    @Qualifier(value="mailSender")
    private JavaMailSenderImpl mailSender;


public EmailService() {
    initContext();
}

private void initContext() {
    RuleManager ruleManager = (RuleManager) applicationContext.getBean("localRuleManager");
    ContextEvidence evidence = new ContextEvidenceEntry(EvidenceType.ROLE, new String("Front Office"));
    ruleManager.addMultipleEvidence(evidence);
}

我在initContext的第一行有一个空指针异常,applicationContext为null

收听频道如下所示启动;

final ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
DirectChannel inputChannel = ac.getBean("receiveChannel", DirectChannel.class);

在添加applicationContext和initContext()行之前,它工作正常。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailService' defined in file [XXXX/EmailService.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [XXXXEmailService]: Constructor threw exception; nested exception is java.lang.NullPointerException

谢谢

吉勒

0 个答案:

没有答案