저는 Spring과 Spring의 통합에 익숙하지 않으며, 수행해야 할 간단한 작업이 있습니다. 그것을 필터링하여 일부 전자 메일의 주제는 정규 표현식을 사용하고 db에 일부 정보를 등록합니다.스프링 통합 메일 인바운드 채널
JavaMailProperties를 설정했는데 테스트에서 읽은 전자 메일의 출력을 제공하지만 실제로는 service-activator
으로 설정하는 메서드는 호출되지 않으며 이것이 실제로 두통이 심해집니다.
<?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.2.xsd
http://www.springframework.org/schema/integration/mail
http://www.springframework.org/schema/integration/mail/spring-integration-mail-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<util:properties id="javaMailProperties">
<prop key="mail.store.protocol">pop3</prop>
<prop key="mail.debug">true</prop>
</util:properties>
<mail:inbound-channel-adapter id="pop3Adapter"
store-uri="pop3://username:[email protected]:110/INBOX"
channel="recieveEmailChannel"
should-delete-messages="false"
auto-startup="true"
java-mail-properties="javaMailProperties"
mail-filter-expression="subject matches '(^Presente+\\s([1-9]{1})+(\\s[-]\\s)+([A-Z]{4,})+(\\s[A-Z]{6,})$)'">
<int:poller max-messages-per-poll="10" fixed-delay="10000"/>
</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="leggiMail" method="processa_mail"/>
<bean id="leggiMail" class="it.jenia.ac.mail.rapportini.LeggiMail">
</bean>
</beans>
가 processa_mail
방법과 함께 LeggiMail
클래스는 매우 간단하다 : 나는이 응용 프로그램을 사용하고
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.stereotype.Service;
@Service
public class LeggiMail {
private static Logger logger = Logger.getLogger(LeggiMail.class);
public static int count_get = 0;
@ServiceActivator
public void processa_mail(MimeMessage mimeMessage) {
count_get++;
logger.debug("porcessa_mail working");
}
테스트 클래스 :
다음 는XML 구성 파일
@ContextConfiguration(locations = { "classpath*:/test-spring-configuration.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
public class LeggiMailTest {
private static Logger logger = Logger.getLogger(LeggiMailTest.class);
@Autowired
LeggiMail lm;
@Test
@Transactional(value = "transactionManager", propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)
public void test_processa_mail(){
logger.debug("Test started");
}
}
로그 Test started
콘솔에 올바르게 표시되지만 로그는 porcessa_mail working
에 표시되지 않습니다.
이 주제에서 발견 한 첫 번째 자습서는 컨텍스트에서 기본적으로 호출되었을 메서드에 대해 이야기했습니다. http://blog.solidcraft.eu/2011/04/read-emails-from-imap-with-spring.html (그리고 컨텍스트가로드 될 때 방법 "processa_mail는"그것은 service-activator
충분히 도움이되지 않았다 서비스 활성화에 대한이 튜토리얼을 읽기의 원인 기본적으로 호출 할 필요가 있다고 말한다. http://docs.spring.io/spring-integration/reference/html/messaging-endpoints-chapter.html
왜 호출해야합니까? 내가 맞으면 응용 프로그램이 시작되고 그 후에 중지됩니다. 또한 왜 두 컨텍스트를로드하고 다른 컨텍스트에서 두 콩을 혼합하는 것이 더 나빠지는지 궁금합니다. 첫눈에 테스트에 결함이 있다고 말할 수 있습니다. –
잘이 (http://blog.solidcraft.eu/2011/04/read-emails-from-imap-with-spring.html) 자습서에 따라 메서드는 기본적으로 호출되어야합니다. 왜 그런지 모르겠지만 이메일을 읽은 후에 "메소드"를 호출하는 해결책을 물어볼 수 있습니까? – softwareplay
나는 간단히 "사이에"절차를 이해할 수 없다 .. – softwareplay