Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot application can't resolve the org.springframework.boot package

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

I am using STS(Spring Tool Suite) and it shows errors about the imports from theorg.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.

like image 400
Orel Bitton Avatar asked Oct 23 '15 11:10

Orel Bitton


People also ask

How do I enable Devtools in Spring Boot?

You can configure global devtools settings by adding a file named . spring-boot-devtools. properties to your $HOME folder (note that the filename starts with “.”). Any properties added to this file will apply to all Spring Boot applications on your machine that use devtools.

Can we run Spring Boot application without @SpringBootApplication?

It's not mandatory to put @SpringBootApplication to create a Spring Boot application, you can still use @Configuration and @EnableAutoConfiguration individually as shown in the example given in the next point.

Does Spring Boot require xml configuration to function?

xml file is required! When required, however, we can take control over parts of the configuration and override the conventions that Spring Boot puts in play. We can also, if we really must, use traditional XML configuration files for some parts of the configuration.


2 Answers

change the version of spring boot parent

<parent>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-parent</artifactId>     <version>1.4.2.RELEASE</version>  </parent> 
like image 74
Nithin Avatar answered Sep 20 '22 14:09

Nithin


Right button on project -> Maven -> Update Project

then check "Force update of Snapshots/Releases"

like image 38
victommasi Avatar answered Sep 23 '22 14:09

victommasi