Cannot Access Org. Springframework. Context. Configurableapplicationcontext Class File
I Am New to Spring Boot, While Trying to Build My First Spring Boot Project (Maven) in Intellij Using Spring Initializer, I Am Getting This Error When I Run My...
I am new to spring boot, while trying to build my first spring boot project (Maven) in intellij using spring initializer, I am getting this error when I run my project after creating it:
cannot access org.springframework.context.ConfigurableApplicationContext class file for org.springframework.context.ConfigurableApplicationContext not found
I followed many tutorials but every time I am getting this error, how to resolve this?
My pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
xsi:schemaLocation="
">
<modelVersion>4.0.0</modelVersion>
<groupId>com.boot</groupId>
<artifactId>das-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>First spring boot app</name>
<description>project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
22 Answers
I was able to fix it by the following steps:
- File -> Invalidate Cache and Restart
- File -> New -> Project from existing source
- Select the pom.xml file just (not the whole project directory) to load the project. Project will be setup automatically.
I am using IntelliJ and gradle for my spring boot application and encountered the same issue.
I resolved it by deleting the auto-generated .iml file under classpath.
Hope it helps anyone who comes after.
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
I am using IntelliJ Idea, if I used "Import project", I faced the same issue. Even after using File -> Invalidate Cache and Restart issue was not resolved.
I closed the project, removed it from the list.
Then used "Open" instead of the "Import Project" button to import to the project. It worked fine. Hope it helps someone.
What worked me is run
mvn package
or
mvn dependency:purge-local-repository
and try invalidating the cache/restart the intellij idea.. Hope that helps
- As the first answer stated, you can try invalidating caches and restarting. I tried that but it didn't work for me. I think it is an IntelliJ problem however.
- Check your maven dependencies if there is an error with the packages.
- I re-imported all my maven dependencies and also checked for the synchronization of version numbers in the pom.xml file. This was able to solve my own problem.
for me just the following fixed it (IDE : Intellij):
- File -> Invalidate Cache and Restart
My fix:
- right click project/module -> Open Module Settings -> Modules
- select only the correct modules
Install Maven command-line tool and then run this command
mvn clean install
After that restart idea and it should work as expected.
Remove .iml files in java and test directory
I was seeing the same error in a tooltip when I hovered over the red-underlined SpringApplication.run call in the main method (Intellij 2019.3 community ed) although the build seemed to go ahead fine. The wavy red underlines annoyed me though.
None of the above solutions seemed to help.
Finally I went to the Project Structure dialog and noticed two things that I fixed:
1) I had named the main module to teamTest, and worried that the 'Test' suffix might trip up some auto configuration behaviours, and
2) I had a somewhat asymmetric module structure (the teamTest module was rooted in the project root, the test module was rooted in the src/test subdir)
I removed the existing teamTest main module and added a new one called teamDemo rooted in the src/main subdir, as a sibling to the existing test module. Then I went into the pom.xml file and renamed the artefact from teamTest to teamDemo in a couple places, as I saw a warning about the pom.xml possibly overriding this change in future.
For good measure I also: - closed the project - removed it from the history - closed Intellij - ran mvn dependency:purge-local-repository in a gitbash window
before running Intellij again and opening the project again.
Red wavy underlines were gone.
Phew! Hope this helps someone else...
I got the same error while creating my project via . All worked well after I selected Java 8 instead Java 11. Maybe this will help some other beginner like me...
For me it was removing the .idea file and then opening the project again choosing the pom.xml file
I was encountering the same issue after loading a new project from the Initializr using Spring 3.0.4 and Java 17. I had done this successfully with two other Spring Boot projects previously the day before and the suggestions above didn't work. I could clearly see the jar containing ConfigurableApplicationContext in the external libraries folder (org.springframework:spring-core-6.0.6). I tried creating a project in the initializr again using the same dependencies that I had used the day before in projects that didn't work. I tried invalidating the cache and restarting, but all came to naught. What worked was
- Close the project
- Delete the .idea folder
- New -> Project from existing sources
- I selected the pom.xml in the dialog, but I am not sure this was necessary.
- Build -> Build Project
Not sure how the .idea folder got messed up or why it affected subsequent projects.
Test runs when I run mvn test. Not if I run it directly as a junit test from the IDE. My issue was similar but not the exact same class not found.
I tried to Invalidate Cache and Restart but didn't work . The problem is a confliction of versions
I was able to solve the problem by
go to select your java and spring versions
go to "explore" which you will find at the bottom of the page
copy the code where version are declared
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>16</java.version>
</properties>
- Invalidate Cache and Restart
Note: make sure to change the roupId and artificatId to yours
File -> Invalidate Cache and Restart did not help in resolving the problem. However, I was able to fix it by deleting the auto-generated .iml file, but I don't fully understand why this was the issue.
In my case one of the maven packages was broken and not installed properly (under .m2 directory) and causing the above issue. Actually the installed jar file was empty for some unknown reason (maybe network fluctuation during download or something)
So I deleted the package folder from .m2 directory and on the next mvn clean install it got downloaded and installed properly and build issues resolved.
However, I saw the actual error by doing mvn clean install from terminal (outside the Intelij). When I did mvn clean install from inside the Intelij, it didn't show me the actual error and instead just showed me cannot access .... error.
So if none of the mentioned solutions worked for you, just navigate to your source code directory in file explorer, in terminal type mvn clean install. Then it'll give you the name of the broken package(s). So you can simply remove them manually and have them installed again by typing mvn clean install
add spring-context-5.1.6.RELEASE.jar file manually on external library and try. it solves the problem.
First of all, don't forget to install the Maven/Gradle IntelliJ plugin if you are using IntelliJ, Then, if still seeing the same error, try to follow the suggestion to import the library. Lastly, invalid cache and restart your IntelliJ, it'll work as expected.
When you import project from a downloaded resource select pom.xml itself not project directory, it will setup project.
For sake of completeness, as one of possible answers not for this problem, but these problems:
If you're using Java 8 (which will be supported till 2030), latest SpringBoot for you is 2.2-2.3, (for Java 8-15), so if you have 3.x.x, e.g., it is a "bad jar" for you, as bytecode version is >52.0 there.
Cache invalidation won't work in this case. Use corresponding LTS spring version.