4

我正在尝试使用 spring 集成电子邮件机制。我使用此链接作为参考:http: //blog.solidcraft.eu/2011/04/read-emails-from-imap-with-spring.html

不幸的是,我在服务器启动时收到一条错误消息:

Caused by: java.lang.IllegalArgumentException: Target object of type [class src.com.project.myEmailReciever] has no eligible methods for handling Messages.
at org.springframework.util.Assert.notEmpty(Assert.java:294)
at org.springframework.integration.util.MessagingMethodInvokerHelper.findHandlerMethodsForTarget(MessagingMethodInvokerHelper.java:348)
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:165)
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:103)
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:107)
at org.springframework.integration.handler.MethodInvokingMessageProcessor.<init>(MethodInvokingMessageProcessor.java:48)
at org.springframework.integration.handler.ServiceActivatingHandler.<init>(ServiceActivatingHandler.java:42)
at org.springframework.integration.config.ServiceActivatorFactoryBean.createMethodInvokingHandler(ServiceActivatorFactoryBean.java:48)
at org.springframework.integration.config.AbstractStandardMessageHandlerFactoryBean.createHandler(AbstractStandardMessageHandlerFactoryBean.java:72)
at org.springframework.integration.config.AbstractSimpleMessageHandlerFactoryBean.createHandlerInternal(AbstractSimpleMessageHandlerFactoryBean.java:89)
at org.springframework.integration.config.AbstractSimpleMessageHandlerFactoryBean.getObject(AbstractSimpleMessageHandlerFactoryBean.java:68)
at org.springframework.integration.config.AbstractSimpleMessageHandlerFactoryBean.getObject(AbstractSimpleMessageHandlerFactoryBean.java:31)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 30 more

显然我的接收类中的功能:

public void receive(MimeMessage mimeMessage) {

//doSomthing
   }

没有资格处理电子邮件..有人知道我该如何解决这个问题吗?

编辑这里是我的类\ xml的:

@Component
@Scope("prototype")
public class MessageFactory {

@Autowired
private ApplicationContext ctx;

private static final Logger logger = LoggerFactory.getLogger(MessageFactory.class);

ObjectMapper mapper = new ObjectMapper();


public boolean receive(MimeMessage mimeMessage) {

    System.out.println("try");
    return true;
   }
}

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: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-3.0.xsd
        http://www.springframework.org/schema/integration/mail
        http://www.springframework.org/schema/integration/mail/spring-integration-mail-2.0.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">true</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="messageFactory" method="receive"/>

<bean id="messageFactory" class="src.com.project.service.factories.MessageFactory">
</bean>

4

2 回答 2

9

此错误通常是配置问题。

可能导致它的条件包括...

  • 配置中的拼写错误method的属性<service-activator/>
  • 该方法不公开
  • requires-reply="true"并且该方法返回 void (就像你的一样)
于 2013-07-20T13:18:54.873 回答
0

我正在使用 Spring Integration 2.2.4 并且遇到了这个问题。我看到另一个帖子说@Header 在某些版本的 Spring Integration 中不起作用。不幸的是,我现在无法升级。因此,选择是尝试使用 @Headers 或使用表达式。我使用了一个表达式,它对我有用......

<service-activator expression="@myService.serviceMethod(headers.customerKey, payload)"/>
于 2014-08-26T14:05:25.670 回答