我一直在使用 spring 集成来开发一个使用 pop 3 协议(protocol)的邮箱监听器,这样它将监听邮箱并使用 pop3 协议(protocol)读取所有邮件 但我开发了一个主类,在该类中我收到错误,我收到的错误位于下面一行
inputChannel.subscribe(new MessageHandler() {
这是编译时错误,表明AbstractSubscribableChannel 类型中的方法 subscribe(MessageHandler) 不适用于参数 (new MessageHandler(){})
下面是主类
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.messaging.MessageHandler;
public class GmailInboundPop3AdapterTestApp {
private static Logger logger = Logger.getLogger(GmailInboundPop3AdapterTestApp.class);
public static void main (String[] args) throws Exception {
ApplicationContext ac = new ClassPathXmlApplicationContext("/test1/src/main/resources/gmail-pop3-config.xml");
DirectChannel inputChannel = ac.getBean("receiveChannel", DirectChannel.class);
inputChannel.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message) throws MessagingException {
logger.info("Message: " + message);
}
});
}
}
请告知如何克服此错误本身
下面还有我的 xml
<int:channel id="receiveChannel" />
<!-- replace 'userid and 'password' wit the real values -->
<int-mail:inbound-channel-adapter id="pop3ShouldDeleteTrue"
store-uri="pop3://[userid]:[password]@pop.gmail.com/INBOX"
channel="receiveChannel"
should-delete-messages="true"
auto-startup="true"
java-mail-properties="javaMailProperties">
<!-- Will poll every 20 seconds -->
<int:poller fixed-rate="20000"/>
</int-mail:inbound-channel-adapter>
<util:properties id="javaMailProperties">
<prop key="mail.pop3.socketFactory.fallback">false</prop>
<prop key="mail.debug">true</prop>
<prop key="mail.pop3.port">995</prop>
<prop key="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
<prop key="mail.pop3.socketFactory.port">995</prop>
</util:properties>
</beans>
最佳答案
检查您的 CLASSPATH 中是否有旧的 Spring Integration 版本。自 4.0 以来,它基于 spring-messaging
。因此,版本<4.0不接受org.springframework.messaging.MessageHandler
- 它必须是org.springframework.integration.core.MessageHandler
。
所以,从我的角度来看,这只是类路径中版本的混合。
关于java - 在 Spring 集成中主程序本身出现编译时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31354245/