首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我已经尝试过将spring集成xml配置转换为java配置。我正面临一些问题,下面我已经讨论过了。

我已经尝试过将spring集成xml配置转换为java配置。我正面临一些问题,下面我已经讨论过了。
EN

Stack Overflow用户
提问于 2017-06-29 06:46:36
回答 1查看 327关注 0票数 0

尝试了下面给出的两种方法,但不起作用。我已经给出了我在下面的方法中所面临的问题。

Xml配置:第一个配置错误:

错误:通过工厂方法进行Bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:未能实例化org.springframework.integration.mail.Pop3MailReceiver:工厂方法'pop3MailReceiver‘引发的异常;嵌套异常是java.lang.NoClassDefFoundError: javax/mail/服务

代码语言:javascript
复制
<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配置:

代码语言:javascript
复制
@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配置:删除第1@Bean公共Pop3MailReceiver pop3MailReceiver()并使用以下方法

代码语言:javascript
复制
    @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、Mail,即使它们在我的maven依赖项中

pom.xml

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-29 07:03:06

正如我从堆栈跟踪中看到的问题中所看到的,它说没有类def错误。

抛出异常;嵌套异常为java.lang.NoClassDefFoundError: javax/mail/Service

这通常意味着类路径或应用程序加载位置缺少mail.jar,检查类路径以查看是否存在所有jar文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44818137

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档