SpringBootTest cannot be resolved to a type

Katrinna L picture Katrinna L · Oct 11, 2016 · Viewed 11.4k times · Source

I have a simple Spring Boot project. I'm using maven for dependency management. The import for SpringBootTest is not recognised so I'm getting:

SpringBootTest cannot be resolved to a type

I can't figure out what the problem is with this.

Here's the pom.xml file:

<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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.sample</groupId>
  <artifactId>SpringBootExample</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>


  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Answer

Chetan Oswal picture Chetan Oswal · Nov 13, 2017

I faced the same trouble. I actually don't understand the actual problem as it will sound quite funny, but when I changed the version of "spring-boot-starter-parent" artifact from 1.5.8.RELEASE to 1.5.7.RELEASE, everything got back to perfect.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.7.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

Try and see what happens with you.