Abdul
Abdul

Reputation: 1208

@SpringBootApplication cannot be resolved to a type In STS

I am very new to STS. I searched for this error in stackoverflow. I didn't find correct matching answer.

I am able to see the class in MavenDependencies seciton in STS but not able to add the annotation in my java class.

enter image description here Your help will be appriciated. Thanks

enter image description here

Upvotes: 24

Views: 81821

Answers (10)

Paul Stevenson
Paul Stevenson

Reputation: 145

in Spring Tool Suite gradle > refresh gradle project should get it all working again

Upvotes: 0

Guilherme Alencar
Guilherme Alencar

Reputation: 1403

I had the same issue, but I am not sure if we got there for the same reason. In my case, the Spring Initializr generated my project with this tag on pom.xml file:

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

But 3.0.0-SNAPSHOT doesn't even exist yet for this artifact. I went to the maven repository page, and I got the most recent one (currently 2.7.0), reloaded the project and it started working.

Upvotes: 0

user12099683
user12099683

Reputation: 1

import the following:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Upvotes: 0

Ashwani Sharma
Ashwani Sharma

Reputation: 499

Neither of the above solutions worked for me as my code was this

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
</parent>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>    
<properties>
    <java.version>1.8</java.version>
</properties>

I was missing the <dependencies> tag which lead to this error.

Upvotes: 1

Miraj Hamid
Miraj Hamid

Reputation: 662

Clear your org/springframework/boot folder under .m2/ file location and run mvn clean install command under project

Upvotes: 0

Foolish
Foolish

Reputation: 4202

Go to your maven repository directory For windows on below path C:\Users\YourUser\.m2\repository\org\springframework\boot Then delete spring-boot-autoconfigure folder.

Now go to eclipse Right click on project -> Maven -> Update Project.

This solved the problem for me.

Upvotes: 70

786543214
786543214

Reputation: 855

Run bellow commands from command line

mvn clean dependency:tree
mvn clean compile

select project and do a maven->update This solved my problem

Upvotes: 5

user2978065
user2978065

Reputation: 1

I had the same problem. You can resolve it with building the project with the "eclipse:eclipse" goal.

Upvotes: -1

Saravanan T
Saravanan T

Reputation: 21

Just change your spring boot version into 1.5.6 from 1.5.8. trust me i have tried every other solution but only this solution worked for me.

Upvotes: 1

FMC
FMC

Reputation: 660

Add the import statement below your package declaration.

import org.springframework.boot.autoconfigure.SpringBootApplication;

You only need to add that annotation to your entry point, not every class. It goes on the same class that holds the main method to start Spring...

    public static void main(String[] args) {
    SpringApplication.run(CourseAPIApp.class, args);
}

Upvotes: 0

Related Questions