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="[email protected]"
mail.smtp.user="[email protected]"
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?
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.
This is a classloading issue. Usually this is because the class is both in a jar in your server and in your application. In this case, you probably want to remove it from your application. Do you have something like mail.jar in your WEB-INF/lib or EAR?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With