Alex Rivera | Logout

Spring--cannot convert javax.mail.session

Asked 2012-01-11T15:19:51.440
9

I am creating a mail session inside of my servlet context and then using JNDI to inject it into my spring framework design. Here's how the context looks:

<Resource name="mail/session" auth="Container"
            type="javax.mail.Session"
            mail.smtp.from="noreply@xxxx.com"
            mail.smtp.user="noreply@xxxx.com"
            mail.smtp.auth="true"
            mail.smtp.starttls.enable="true"
/>

And where I'm bringing it in:

  <bean id="smtpSession" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/mail/session"/>
  </bean>

and where I'm injecting it into the spring java mail sender:

  <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
      <property name="host" ref="smtpHost"/>
      <property name="password" ref="smtpPassword"/>
      <property name="port" ref="smtpPort"/>
      <property name="username" ref="smtpFrom"/>
      <property name="session" ref="smtpSession"/>
  </bean>

Now here's the message I'm getting:

Caused by: java.lang.IllegalStateException: Cannot convert value of type [javax.
mail.Session] to required type [javax.mail.Session] for property 'session': no m
atching editors or conversion strategy found
        at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(Ty
peConverterDelegate.java:231)
        at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrap
perImpl.java:447)
        ... 51 more

Uh, what???? Why is it trying to convert it?

Edit
Report

1 Answer

23

You most likely have two copies if javax.mail.Session on your classpath. One probably comes from the appserver's internal libraries, the other is likely packed in your app's lib directory. The two copies will clash when you try and use them like this.

Remove the one in your app's lib directory, and try again.

answered 2012-01-11T15:23:37.553

Your Answer