title: ClassNotFoundException on Spring JavaMailSenderImpl in JUnit test with Spring Boot
body: <p>I've only just started a new project with Spring Boot, which I'm trying to get to grips with.  I'm using Spring Tool Suite which has created a Spring Boot project for me and loaded some dependencies which I know I'll need further down the line (specifically Spring Batch and Spring Data)</p>
  
  <p>This is my pom.xml:</p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.4.2.RELEASE&lt;/version&gt;
      &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-batch&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- JDBC driver --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.microsoft.sqlserver&lt;/groupId&gt;
          &lt;artifactId&gt;mssql-jdbc&lt;/artifactId&gt;
          &lt;version&gt;6.1.0.jre8&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>I've been reading the reference documentation and know that I'll need mail at some point down the line, so I added this to my <code>application.properties</code> file:</p>
  
  <pre><code>spring.mail.host=my.mail.host
  </code></pre>
  
  <p>I then tried to build the application with <code>mvn package</code> but it threw an error in the tests.  The test consists of the following:</p>
  
  <pre><code>package its.idcard.batch;
  
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.test.context.junit4.SpringRunner;
  
  @RunWith(SpringRunner.class)
  @SpringBootTest
  public class IdCardBatchApplicationTests {
  
      @Test
      public void contextLoads() {
      }
  
  }
  </code></pre>
  
  <p>So all it's doing is trying to load the application context, but it fails with a ClassNotFoundException on org.springframework.mail.javamail.JavaMailSenderImpl.</p>
  
  <p>I know this is a problem purely with the test, as after adding a bit of Spring Data stuff, and skipping tests in maven, my stub application runs as expected (and looking in the generated jar, I can see that spring-context-support-4.3.4-RELEASE.jar is present, containing the offending class), so it appears to be a classpath issue on the tests but I'm stumped.  If I comment out the <code>spring.mail.host</code> line in the properties file, the test runs without problems.</p>
  
  <p>Any ideas would be gratefully appreciated.</p>