ReyAnthonyRenacia
ReyAnthonyRenacia

Reputation: 17651

Spring Tool Suite: Cannot Execute a Simple Demo because of Spring Boot Build Path ERROR

The Error is as follows:

Description Resource Path Location Type The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.context.ConfigurableApplicationContext. Fix the build path then try building this project springbootdemo Unknown Java Problem

2 ERROR items:

Description Resource Path Location Type The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files MainActivity.java /springbootdemo/src/main/java/springbootdemo line 10 Java Problem

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

@SpringBootApplication
public class MainActivity {

    public MainActivity() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        //this is where the ERROR happens beginning at 
        //  "SpringApplication.run(MainActivity.class, args);"
        ApplicationContext ctx = SpringApplication.run(MainActivity.class, args);

    }
}

pom.xml

<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>labs.noogui.springbootquickstart</groupId>
  <artifactId>course-api</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>springboot course-api</name>

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

<dependencies>

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

</dependencies>

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>  
<properties>
    <java.version>1.8</java.version>
</properties>  

</project>

Project Structure:

enter image description here

enter image description here

 **Spring Tool Suite** 

Version: 3.9.4.RELEASE
Build Id: 201804120921
Platform: Eclipse Oxygen.3a (4.7.3a)

I'm following the Spring Boot tutorial from Edureka!

How do I fix this build path error? I mean, this is like a spring boot hello world and I'm already running into errors?

Upvotes: 0

Views: 1333

Answers (3)

ReyAnthonyRenacia
ReyAnthonyRenacia

Reputation: 17651

Thanks for the folks who tried to help but I found out that the problem is with maven's 'corrupted' repository (again). So as always, deleting the .m2/repository and updating your maven project resolves the issue.

Related post in this github forum. This is a recurring issue with maven.

Upvotes: 0

Alex Minjun Yu
Alex Minjun Yu

Reputation: 3707

You are using ApplicationContext from org.apache.catalina.core.

Import and use this org.springframework.context.ApplicationContext instead.

Your IDE is showing compile errors. Error message should probably lead you to the right direction.

Upvotes: 2

Kathirvel Subramanian
Kathirvel Subramanian

Reputation: 684

Just use below code,

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

@SpringBootApplication
public class MainActivity {

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

 }
}

or if you want to use ApplicationContext to start the application then use below line but both are almost same.

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

@SpringBootApplication
public class MainActivity {

public static void main(String[] args) {
    ApplicationContext ctx = SpringApplication.run(MainActivity.class, args);

 }
}

Upvotes: 1

Related Questions