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.

5
  • 1
    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 corrupted
    – Nadir
    Oct 17, 2016 at 12:23
  • The jars are present but how do I verify whether or not they are corrupted, and if they are, how do I fix them?
    – user2719805
    Oct 17, 2016 at 12:24
  • 1
    open them with 7zip or something similar and check if the classes are there
    – Nadir
    Oct 17, 2016 at 12:25
  • Try this link.
    – RITZ XAVI
    Oct 17, 2016 at 12:27
  • @RITZXAVI I have tried that link but it did not fix the issue. @Nadir 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\context
    – user2719805
    Oct 17, 2016 at 12:32

12 Answers 12

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.

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 though
    – user2719805
    Oct 17, 2016 at 14:33
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

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

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.

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.
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.

0

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

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>
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).

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.
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.
    – Community Bot
    Oct 16, 2021 at 21:14
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

-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

1
  • 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. Nov 5, 2019 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.