I struggled with this very problem for the email service class, encoded as follows:
@Service("emailService") public class EmailService { @Autowired private JavaMailSenderImpl mailSender; ... public void send(...) {
I stumbled upon a solution while reading about a related topic. The key point is that the JavaMailSender interface JavaMailSender defined in applicationContext.xml as the Spring class JavaMailSenderImpl .
Step 1: The application context file has been modified to include the following bean definition:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl" p:host="myMailserver.mycompany.com" />
Step 2: The email service class has been modified to look like this:
@Service("emailService") public class EmailService { @Autowired private JavaMailSender mailSender;
Voila! Spring is happy. I was , although I would like to hear the correct explanation of the original error.
source share