Spring boot application cannot resolve org.springframework.boot package

I installed the spring boot project using the Spring Initializer , several times I tried to create a new project or play with dependencies everything seems to be in place.

I am using STS (Spring Tool Suite) and it shows errors about importing from org.springframework.boot package. Running the application throws an exception:

Exception in thread "main" java.lang.Error: unresolved compilation Problem: SpringApplication cannot be resolved.

com.example.DemoApplication:

 import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } 

pom.xml:

 <?xml version="1.0" encoding="UTF-8"?> <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.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>demo</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <start-class>com.example.DemoApplication</start-class> </properties> <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> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 

I am using Java 1.8 with STS.

+25
java spring spring-mvc maven
source share
15 answers

change the spring version of the boot parent

 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.2.RELEASE</version> </parent> 
+23
source share

Right button in the project → Maven → Update project

then check the box "Force snapshot / release updates"

+16
source share

From your pom.xml, try deleting spring repository entries, by default it will be loaded from the maven repository. I tried with 1.5.6.RELEASE and worked very well.

+4
source share

If the next step does not work:

Replaced my Spring Download 1.4.2.RELEASE in 1.5.10.RELEASE

  • Right click on the project and -> Maven-> Download Resources
  • right click on the project -> Maven-> Update Project

The cause of this error may be several versions of the same file downloaded to the folder of your local maven storage.

So, follow these steps to clear all existing repository banks and load everything from the beginning based on the dependencies defined in your POM.xml ..

  • Go to the build path. Check out the Maven repository in the added library section.
  • Choose any jar and mouse. it will show the location of the local repository. this is usually: user / .m2 / repository / ....
  • Go to the location. and delete the repository folder.
  • Now right click on your project .. do Maven -> update maven.
    This will solve the problem of your dependencies. since Maven will try to download all the items from the repository again and build the project.
+4
source share

In my project, the dependency on spring-boot-starter-parent has been updated from 2.0.0.release to 2.0.5.relese. This solved the problem. Import org.springframework.boot.SpringApplication cannot be resolved.

+3
source share

I had the same issue when I tried to work with the spring bootboot application. I tried using the latest spring-boot from the official spring-boot site .

Like today, the latest version is 1.5.4.RELEASE . But I keep getting compilation issues on my eclipse IDE, regardless of a few cleanup steps. I downgraded the spring-boot version to 1.5.3.RELEASE and it just worked! Some of my previous projects used the old version, which made me try this option.

+1
source share

I encountered the same problem during my first Spring boot application.

In the tutorial, I could see the following dependency to run the sample application

  • Spring Download 1.4.2.RELEASE
  • Maven 3
  • java 8

I did the same, my Spring STS recognizes the whole class, but when I comment out my main class using @SpringBootApplication, it does not recognize this class, while I could see that the jar was available in the class path.

I have a solution to problems

  • Replaced my Spring Boot 1.4.2.RELEASE in 1.5.3.RELEASE
  • Right click on the project and -> Maven-> Download Resources
  • right click on the project -> Maven-> Update Project

After that he worked.

thanks

+1
source share

When you launch the application as a jar, your Manifest.MF file should know which class has the main method.

To add this information when SpringBoot compiles your code, add the start-class property to your pom file.

eg:.

 <properties> <start-class>com.example.DemoApplication</start-class> </properties> 
0
source share

There may be a problem with the JAR files in the local Maven repository. Try deleting the .m2 / repository folder and click Maven -> Update Project ... again so that Maven downloads the dependencies again. I tried this and it worked for me.

0
source share

There is no need to delete the relative path. Just change the parentframe version of Springframework. The next version 2.1.2 is working successfully.

 <?xml version="1.0" encoding="UTF-8"?> <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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.appsdeveloperblog.app.ws</groupId> <artifactId>mobile-app-ws</artifactId> <version>0.0.1-SNAPSHOT</version> <name>mobile-app-ws</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <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> <dependency> <groupId>com.appsdeveloperblog.app.ws</groupId> <artifactId>mobile-app-ws</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 
0
source share

My worked by adding

 <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-autoconfigure --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> <version>2.1.3.RELEASE</version> </dependency> 

instead of directly using other core dependencies, I have no idea why.

0
source share

The solution is to change the Spring version in the pom.xml file

 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> 
0
source share

Try it, it might work for you too.

  1. Open a command prompt and go to the project folder.
  2. Build project (for Maven, run mvn clean install )
  3. After a successful build,
    • Open your project on any IDE (intellij / eclipse).
    • Restart your IDE if it is already open.

This worked for me on both v1.5 and v2.1

0
source share

This answer may be off topic to most readers. In my case, the dependency was not updated, and "mvn clean" did not work, since my Wi-Fi network in the office is very secure, leaving a "connection timeout". (the same respect GitHub pushes and does not work) I just switched to training with my phone and it works. Silly, off-topic for most, but it can help in some very specific cases.

0
source share

Delete the repository folder from "C: \ Users \ usename.m2" and recreate or update the maven project.

-one
source share

All Articles