Ameet
Ameet

Reputation: 341

SpringBootApplication can not be resolved to a type error in Spring tool suite and maven

I have created the maven project in spring tool suite. I created the pom.xml with required dependencies but facing error as "SpringBootApplication can not be resolved to a type". I have tried a couple of solutions like Maven -> Update Project..., Clean Project, deleted local repository directory of Maven (.m2), etc... also I tried creating another maven project but still the same error.

I think this is eclipse spring tool suite problem with maven. Is there any solution like patch by eclipse or anything else? Thanks in advance!

Pom.xml as follows

<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>io.javabrains.springbootquickstart</groupId>
    <artifactId>cource.api</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Java Brains Cource API</name>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
    </parent>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.8.RELEASE</version>
            <type>pom</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <properties>
        <java.version>1.8</java.version>
    </properties>
</project>

Upvotes: 1

Views: 9347

Answers (2)

Kumaresh Babu N S
Kumaresh Babu N S

Reputation: 1698

<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>io.javabrains.springbootquickstart</groupId>
<artifactId>cource.api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Cource API</name>

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<properties>
    <java.version>1.8</java.version>
</properties>

</project>

Copy/Paste it in your POM.xml. Update the Maven project and it will fetch the required JARs.

Upvotes: 0

helospark
helospark

Reputation: 1460

You did not add the correct dependencies.

You should add

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

as a dependency (in <dependencies>) instead of spring-boot-starter-parent. Parent just defines the versions but does not actually add any dependency (you use it as a <parent> in Maven).

If you have test, also add spring-boot-starter-test.

I would also suggest to use https://start.spring.io/ to generate a working Spring Boot base project (also available from STS in File->new->Other->Spring Starter project).

Upvotes: 3

Related Questions