2017-06-29 1 views
0

以下の2つのアプローチを試みたが、うまくいかなかった。私は以下のアプローチに直面している問題を与えました。
XML設定:第一設定でエラー:私は春の統合XML設定をJavaの設定に変換しようとしました。私は以下で議論したいくつかの問題に直面している。

Error : Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.mail.Pop3MailReceiver]: Factory method 'pop3MailReceiver' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/mail/Service

<int:channel id="receiveEmailChannel" /> 
    <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> 

    <int-mail:inbound-channel-adapter id="pop3ShouldDeleteTrue" 
     store-uri="pop3://[user name]:[pwd]pop.gmail.com/INBOX" 
     channel="receiveEmailChannel" should-delete-messages="false" 
     auto-startup="true" java-mail-properties="javaMailProperties"> 

     <int:poller fixed-rate="5000" max-messages-per-poll="5"></int:poller> 
    </int-mail:inbound-channel-adapter> 




    <int:channel id="attachment-insert-channel" /> 
    <int-jdbc:outbound-channel-adapter 
     channel="attachment-insert-channel" data-source="dataSource" query="${attachment-insert-query}"> 
    </int-jdbc:outbound-channel-adapter> 


    <int:channel id="printSqlResult" /> 
    <int-jdbc:outbound-channel-adapter 
     channel="printSqlResult" data-source="dataSource" query="${insert-query}"> 
    </int-jdbc:outbound-channel-adapter> 

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
     destroy-method="close"> 
     <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
     <property name="url" value="jdbc:mysql://localhost:3306/ap_mail" /> 
     <property name="username" value="root" /> 
     <property name="password" value="" /> 
    </bean> 


</beans> 

第一のjavaの設定:

@Configuration 
@EnableIntegration 
public class MailConfig { 

    @Bean 
    public DirectChannel inputChannel() { 
     return new DirectChannel(); 
    } 

    private Properties javaMailProperties() { 
     Properties javaMailProperties = new Properties(); 

     javaMailProperties.setProperty("mail.imap.socketFactory.class","javax.net.ssl.SSLSocketFactory"); 
     javaMailProperties.setProperty("mail.imap.socketFactory.fallback","false"); 
     javaMailProperties.setProperty("mail.store.protocol","imaps"); 
     javaMailProperties.setProperty("mail.debug","true"); 

     return javaMailProperties; 
    } 

    @Bean 
    public Pop3MailReceiver pop3MailReceiver() { 
     Pop3MailReceiver receiver = new Pop3MailReceiver("pop3://[un]:[pwd]@pop.gmail.com/INBOX"); 
     receiver.setJavaMailProperties(javaMailProperties()); 
     receiver.setShouldDeleteMessages(false); 
     //receiver.setChannelResolver((DestinationResolver<MessageChannel>) inputChannel()); 
     return receiver; 
    } 

} 

第二のjavaの設定:豆公共Pop3MailReceiver pop3MailReceiver @取り除か第一()と、この

を使用
@Bean 
    public IntegrationFlow pop3MailFlow() { 
     return IntegrationFlows 
       .from(Mail.pop3InboundAdapter("localhost", "995", "user", "pw") 
       .javaMailProperties(p -> p.put("mail.debug", "true")),e -> e.autoStartup(true) 
       .poller(Pollers.fixedDelay(60000))) 
       .channel(MessageChannels.queue("pop3Channel")) 
       .get(); 
    } 

この問題はIntegrationFlowsをインポートできませんが、私は、スタックにあなたの質問からわかるように、彼らは私のMavenの依存関係に

のpom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.muraai.mail</groupId> 
    <artifactId>mail</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 

    <properties> 
     <java.version>1.8</java.version> 
    </properties> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.4.RELEASE</version> 
    </parent> 

    <dependencies> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.integration</groupId> 
      <artifactId>spring-integration-java-dsl</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.integration</groupId> 
      <artifactId>spring-integration-mail</artifactId> 
     </dependency> 

    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 

       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

答えて

0

していてもメール

が例外をスローしたいかなるクラスのdefのエラーを言っていないトレース。ネストされた例外はjava.lang.NoClassDefFoundErrorです:

通常、mail.jarがクラスパスまたはアプリケーションがロードされている場所から見つからないことを意味します。クラスパスを調べて、すべてのjarファイルが存在するかどうか。

+0

これは問題なく動作しますが、この方法ではチャネルを指定する方法があります。あなたは私の2番目の設定を確認できますか –

+0

2番目の設定でどのようなエラーが発生しているのかをスタックトレースで共有できますか – Automator1992

関連する問題