My Spring.xml is something like this:

<beans>
	<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
		<property name="host" value="_local-mail-server_" />
	</bean>


	<bean id="businessLogic" class="com.logic.BusinessLogicImpl">
		<property name="mailSender" ref="mailSender"></property>
</bean>
</beans>

And bean definition is as below:

import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;

public class BusinessLogicImpl implements BusinessLogic {

	private MailSender mailSender;

	public void setMailSender(MailSender mailSender) {
		this.mailSender = mailSender;
	}

	@Override
	public void execute() {
        SimpleMailMessage msg = new SimpleMailMessage();
        msg.setFrom(_senderAddress_);
        msg.setTo(_receiverAddress_);
        msg.setText("Hello, just sending you this message.");
    
        try {
            mailSender.send(msg);
        } catch(MailException ex) {
            // log it and go on
            System.err.println(ex.getMessage());
        }
    }

}

when I run this program i get exception as below:

Jul 10, 2009 4:19:25 PM org.springframework.core.CollectionFactory <clinit>
INFO: JDK 1.4+ collections available
Jul 10, 2009 4:19:25 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [C:\data\test_workspace\SpringMailSender\spring.xml]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'businessLogic' defined in file [C:\data\test_workspace\SpringMailSender\spring.xml]: Cannot resolve reference to bean 'mailSender' while setting bean property 'mailSender'; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'mailSender' defined in file [C:\data\test_workspace\SpringMailSender\spring.xml]: Class that bean class [org.springframework.mail.javamail.JavaMailSenderImpl] depends on not found; nested exception is java.lang.NoClassDefFoundError: javax/mail/MessagingException
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'mailSender' defined in file [C:\data\test_workspace\SpringMailSender\spring.xml]: Class that bean class [org.springframework.mail.javamail.JavaMailSenderImpl] depends on not found; nested exception is java.lang.NoClassDefFoundError: javax/mail/MessagingException
Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at org.springframework.util.ClassUtils.forName(ClassUtils.java:160)
	at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:320)
	at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:901)
	at org.springframework.beans.factory.support.AbstractBeanFactory.checkMergedBeanDefinition(AbstractBeanFactory.java:865)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:243)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:167)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:219)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:115)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:798)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:589)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:389)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:256)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:167)
	at MailSenderDemo.main(MailSenderDemo.java:12)
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	... 16 more

Please help solving this problem. I tried using different configuration but it did not worked.

You need the mail.jar in your classpath; you need to download the JavaMail jars if you already don't have them.

You would also be needing the Java Activation Framework libraries [activation.jar] if you are not using Java 6.

You need the mail.jar in your classpath; you need to download the JavaMail jars if you already don't have them.

You would also be needing the Java Activation Framework libraries [activation.jar] if you are not using Java 6.

Thanks it works now.

This question has already been answered. Start a new discussion instead.