Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaMail with Spring - Missing Imports

Tags:

java

spring

I am getting a

The import cannot be resolved

error for the following imports,

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

I have the following libraries in the classpath, but I not sure which jar file has the above-mentioned imports. Does anybody have any idea?

     org.springframework.aop-3.1.1.RELEASE.jar
     org.springframework.asm-3.1.1.RELEASE.jar
     org.springframework.beans-3.1.1.RELEASE.jar
     org.springframework.context-3.1.1.RELEASE.jar
     org.springframework.core-3.1.1.RELEASE.jar
     org.springframework.expression-3.1.1.RELEASE.jar
     org.springframework.jdbc-3.1.1.RELEASE.jar
     org.springframework.orm-3.1.1.RELEASE.jar
     org.springframework.web-3.1.1.RELEASE.jar
like image 757
Sachin Avatar asked Aug 23 '12 18:08

Sachin


3 Answers

You are missing org.springframework.context.support-3.1.1.RELEASE.jar

or

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>3.1.1.RELEASE</version>
</dependency>

if you're using Maven.

like image 103
Reimeus Avatar answered Oct 20 '22 08:10

Reimeus


You should add to pom.xml:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4</version>
</dependency>

and

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>4.0.5.RELEASE</version>
</dependency>

$mvn clean install worked for me. :)

like image 28
Nicolas Moraes Avatar answered Oct 20 '22 07:10

Nicolas Moraes


You could use a Spring email boot starter dependency for mail, see below:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
    <version>2.0.1.RELEASE</version>
</dependency>

This will contain both spring-context-support & javax.mail dependencies

like image 44
Kevin Crain Avatar answered Oct 20 '22 07:10

Kevin Crain