gpt4 book ai didi

Spring 集成:imap - error: Target object of type [class myEmailReciever] has no eligible methods for handling Messages

转载 作者:行者123 更新时间:2023-12-01 23:31:49 26 4
gpt4 key购买 nike

我正在尝试使用 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>

最佳答案

此错误通常是配置问题。

可能导致它的情况包括...

  • 拼写错误 method <service-activator/> 中的属性配置
  • 该方法不是公开的
  • requires-reply="true"该方法返回 void (就像你的一样)

关于 Spring 集成:imap - error: Target object of type [class myEmailReciever] has no eligible methods for handling Messages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17761951/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com