MockMultipartFile cannot be resolved to a type
<p>I am writing code for a spring program, and I need to convert a <code>File</code> object to a <code>MultipartFile</code> object. I am trying to do this by using the <code>MockMultipartFile</code> class:</p>

<pre><code>FileInputStream input = new FileInputStream(toUpload);
MultipartFile multipartFile = new MockMultipartFile("file",
                toUpload.getName(), "text/json", IOUtils.toByteArray(input));
</code></pre>

<p>However, I keep getting the error <code>MockMultipartFile cannot be resolved to a type</code>. Why is this? If it helps, I'm using Maven, in case it may be a dependency error that I don't know about.</p>

<p>I also tried to do this using <code>CommonsMultipartFile</code>. That code is here (<code>toUpload</code> is the <code>File</code> object I am trying to convert):</p>

<pre><code>DiskFileItem fileItem = new DiskFileItem("file", "text/plain", false, toUpload.getName(), (int) toUpload.length() , toUpload.getParentFile());
fileItem.getOutputStream();
MultipartFile multipartFile = new CommonsMultipartFile(fileItem);
</code></pre>

<p>When I try this method, I get the error <code>The constructor CommonsMultipartFile(DiskFileItem) is undefined</code>. Why is that?</p>

<p>EDIT: Here is our pom.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;gs-uploading-files&lt;/artifactId&gt;
    &lt;version&gt;0.1.0&lt;/version&gt;

    &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.3.5.RELEASE&lt;/version&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-thymeleaf&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
            &lt;optional&gt;true&lt;/optional&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;commons-fileupload&lt;/groupId&gt;
            &lt;artifactId&gt;commons-fileupload&lt;/artifactId&gt;
            &lt;version&gt;1.3.1&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;

    &lt;properties&gt;
        &lt;java.version&gt;1.8&lt;/java.version&gt;
    &lt;/properties&gt;

    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;

&lt;/project&gt;
</code></pre>