如何为Java邮件会话配置延迟加载JndiObjectFactoryBean

时间:2015-06-30 12:46:37

标签: java spring javamail lazy-loading spring-ioc

我有一个要求,即我的Spring JndiObjectFactoryBean必须对我的jetty服务器中配置的Java邮件会话进行延迟查找

以下是我的jetty.xml中的邮件会话声明

 <New id="mailSessionId" class="org.mortbay.jetty.plus.naming.Resource">
 <Arg>mail/GmailMailSession</Arg>
 <Arg>
  <New class="org.mortbay.naming.factories.MailSessionReference">
    <Set name="user">xxx@gmail.com</Set>
    <Set name="password">xxx</Set>
    <Set name="properties">
      <New class="java.util.Properties">
        <Put name="mail.host">smtp.gmail.com</Put>
        <Put name="mail.debug">true</Put>
        <Put name="mail.smtp.auth">true</Put>
        <Put name="mail.smtp.starttls.enable">true</Put>

      </New>
    </Set>
  </New>
</Arg>
</New>

在我的Spring bean定义文件中,我有以下bean定义

<bean id="dsrouterMailSession" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="mail/GmailMailSession" />
            <property name="resourceRef" value="true" />
            <property name="proxyInterface" value="javax.mail.Session"></property>
            <property name="lookupOnStartup" value="false" />
        </bean>

我不希望Spring在启动时查找邮件/ GmailMailSession。所以我设置了lookupOnStartup&#39;属于&#39; false&#39;。如果我设置了lookupOnStartup&#39; to false Spring希望我提供一个proxyInterface。我搜索了很多,但找不到邮件会话的界面。我尝试设置&#34; javax.mail.Session&#34;这是一个班级。我得到了以下明显的异常

Caused by: java.lang.IllegalArgumentException: [javax.mail.Session] is not an interface
at org.springframework.aop.framework.AdvisedSupport.addInterface(AdvisedSupport.java:216)
at org.springframework.aop.framework.AdvisedSupport.setInterfaces(AdvisedSupport.java:205)
at org.springframework.jndi.JndiObjectFactoryBean$JndiObjectProxyFactory.createJndiObjectProxy(JndiObjectFactoryBean.java:323)
at org.springframework.jndi.JndiObjectFactoryBean$JndiObjectProxyFactory.access$000(JndiObjectFactoryBean.java:307)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:200)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)

我的问题是有没有可用于Java邮件会话的界面,我可以将其设置为&#39; proxyInterface&#39;并使懒惰的查找工作?

0 个答案:

没有答案