The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files
Asked Answered
L

12

17

I am following the tutorial at spring.io to build a spring app using spring boot.

I can get the program to run perfectly on one computer. When I try on a different computer I get the following error

The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files

I have tried deleting and adding my JRE Systems Library (JDK 1.8), as well as cleaning and updating the project using maven, and even deleting and re-importing the entire project. All of these methods have shown no success.

My pom file is

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

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

  <groupId>test.api</groupId>
  <artifactId>api.test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>api.test Maven Webapp</name>
  <url>http://maven.apache.org</url>

  <dependencies>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
     </dependency>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-actuator</artifactId>
     </dependency>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
     </dependency>   
  </dependencies>

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

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

</project>

The class that is giving me the error is the HelloWorldConfiguration.java class

package hello;

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

@SpringBootApplication
public class HelloWorldConfiguration {

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

}

Any help would be greatly appreciated. Thank you.

Labrie answered 17/10, 2016 at 12:20 Comment(5)
on the second machine where it is not working, verify in your local m2 repo that the maven dependencies are ok, meaning the jars are present and not corruptedFloydflss
The jars are present but how do I verify whether or not they are corrupted, and if they are, how do I fix them?Labrie
open them with 7zip or something similar and check if the classes are thereFloydflss
Try this link.Brokendown
@RITZXAVI I have tried that link but it did not fix the issue. @Floydflss Checking again I am not sure the jars are present. in .m2 I have ...\.m2\repository\org\springframework\spring-context not ...\.m2\repository\org\springframework\contextLabrie
I
42

Your Maven cache is corrupted on the second machine. The JAR can't be opened, that's why you get this exception.

You can fix that by running this command on the second machine for that project:

mvn dependency:purge-local-repository

If that doesn't work, try remove your local repo on that machine (~/.m2/repository/org/springframework) and run mvn package again.

Isolationism answered 17/10, 2016 at 14:7 Comment(1)
I think I have a bigger issue hidden somewhere. I am now getting Failed to instantiate SLF4J LoggerFactory when I try to run the code. Thank you for your help thoughLabrie
I
12

I also faced the same issue before. Some dependency corruption might have occurred. You can purge and re-resolve the dependencies. For that :

  1. go to the project location where the pom.xml is present.
  2. open a command prompt there and enter the command below :

    mvn dependency:purge-local-repository -DreResolve=true

Itagaki answered 16/1, 2018 at 2:56 Comment(0)
F
3

I had the same issue and I followed these steps to fix it:

1. Close Eclipse

2. Remove all files inside the repository folder .m2/repository

3. reopen Eclipse and update your Maven project

Fairlie answered 22/5, 2018 at 11:8 Comment(0)
L
1

I had the same problem. I resolved this my deleting the local repository directory of Maven (.m2) on your local computer. It resolved the problem for me.

Lavinialavinie answered 11/12, 2016 at 19:25 Comment(0)
S
1
  1. Find out the version of spring-context your project uses:

(in Eclipse : Project Explorer -> [your project] -> Maven Dependencies)

or

mvn dependency:tree

Lists all dependencies for your project

  1. Delete the folder org/springframework/spring-context/5.0.9.RELEASE from your maven repository .m2/repository. Assuming 5.0.9.RELEASE is the spring-context release version.
Squeaky answered 7/10, 2018 at 14:47 Comment(0)
H
0

this conflict occurs, because some of your dependencies have corrupted.follow this:-> for removing this conflict just go in to your .m2 folder open repository and delete all the files from that folder. and now open your project go in debug do maven clean and after cleaning and all downloading just update your maven projet. and your conflict will have been going to resolve.

Hedron answered 26/8, 2018 at 12:4 Comment(0)
R
0

I too have same problem, I resolved by removing .m2/repository/org folder,later did maven updated form STS.

Rentier answered 28/8, 2018 at 10:7 Comment(0)
T
0
Add bellow dependancy


<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.3.7.RELEASE</version>
</dependency>
Tephra answered 21/7, 2020 at 17:39 Comment(0)
D
0

It may be because some of the dependency is not resolved correctly. You can try to change/de-grade version of "spring-boot-starter-parent" to other working project in your local. E.g. mine Error gone by setting "spring-boot-starter-parent" to "1.5.9.RELEASE" from "2.3.0.RELEASE" (that version was working for other project).

Drought answered 17/9, 2020 at 12:3 Comment(0)
M
0

My answer is too late, but maybe helps others.

I had the same issue while using Eclipse IDE with spring project that I made using start.spring.io. The way I fixed it:

  1. Right-click on your project.
  2. Runs As.
  3. Maven Install.
Mcclanahan answered 16/10, 2021 at 20:52 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Tarpan
C
0

For me ,first answer only works when open the child project as a new project in a new window . You can try delete main.iml or xxx.iml in your child project src\main\main.iml. That works for me EDIT: dont worry, main.iml is auto generated by idea

Couple answered 1/10, 2022 at 10:22 Comment(0)
L
-1

I also faced the same issue and to resolve this I downloaded the jar and added as an external jar. Here is the download link: http://www.java2s.com/Code/Jar/o/Downloadorgspringframeworkcontextjar.htm

Lenient answered 5/11, 2019 at 12:22 Comment(1)
A repeatable solution is preferable. There should be a way of ensuring the environment and the dependencies listed in the pom result in the same behavior.Wriest

© 2022 - 2024 — McMap. All rights reserved.