使用Spring集成从imap读取电子邮件不起作用

时间:2012-12-17 08:44:28

标签: spring imap spring-integration

我正在尝试an example。在示例中,它提到了使用spring-integration 2.0.3,但我得到了一个N​​ullPointerExcpetion并解决它,我遵循的是mentioned here。但是如果我使用spring-integration 2.1那么我认为它需要spring 3.0。

问题: 是否可以使用Spring版本2.5并使用来自imap的读取电子邮件进行弹簧集成?

以下是我项目中设置的maven依赖项:

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>2.5.6</version>
    </dependency>
...
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>2.1.3.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.integration</groupId>
    <artifactId>spring-integration-mail</artifactId>
    <version>2.1.3.RELEASE</version>
</dependency>

弹簧component.xml文件

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mail="http://www.springframework.org/schema/integration/mail"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    http://www.springframework.org/schema/integration/mail
    http://www.springframework.org/schema/integration/mail/spring-integration-mail-2.1.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-2.0.xsd">


    <util:properties id="javaMailProperties">
    <prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
    <prop key="mail.imap.socketFactory.fallback">false</prop>
    <prop key="mail.store.protocol">imaps</prop>
    <prop key="mail.debug">false</prop>
</util:properties>

<mail:inbound-channel-adapter id="imapAdapter"
                                  store-uri="imaps://<username>:<password>@imap.googlemail.com:993/INBOX"                                    
                                  channel="recieveEmailChannel"                                         
                                  should-delete-messages="false"
                                  should-mark-messages-as-read="true"                                     
                                  auto-startup="true"
                                  java-mail-properties="javaMailProperties">
    <int:poller fixed-delay="5" time-unit="SECONDS"/>
</mail:inbound-channel-adapter>

<int:channel id="recieveEmailChannel">        
    <int:interceptors>
        <int:wire-tap channel="logger"/>
    </int:interceptors>
</int:channel>

<int:logging-channel-adapter id="logger" level="DEBUG"/>

<int:service-activator input-channel="recieveEmailChannel" ref="emailReceiverService" method="receive"/>

<bean id="emailReceiverService" class="com.mycompany.DefaultEmailReceiverUtilService">
</bean>

EmailNotificationTest.java

public class EmailNotificationTest extends
    AbstractDependencyInjectionSpringContextTests

{

public static final String SOURCE_VERSION_ID = "$Id$";

    //Who ever wants to run this testcase ,Please uncomment this method
   protected String[] getConfigLocations()
    {
         return new String[]
        { "classpath:META-INF/spring/component.xml" };
    }

public void testSimpleEmailNotification()
{

}
}

如果我运行我的测试用例,我收到以下异常:

org.springframework.beans.factory.BeanDefinitionStoreException:从类路径资源[META-INF / spring / component.xml]解析XML文档的意外异常;嵌套异常是java.lang.NoClassDefFoundError:org / springframework / scheduling / support / PeriodicTrigger     在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)     在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)     在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)     在org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)     在org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)     在org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)     在org.springframework.test.AbstractSingleSpringContextTests.createApplicationContext(AbstractSingleSpringContextTests.java:198)     在org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:179)     在org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:158)     在org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:105)     在org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:87)

1 个答案:

答案 0 :(得分:1)

我没有找到简单的Spring Integration - &gt;春季版表。这是你能做的:

您将立即看到需要哪个Spring版本。例如,使用Spring Integration 2.0.0,您将看到它依赖于Spring 3.0.5。