Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import ClassPathXmlApplicationContext

I learning Java Spring Framework by listening to the "Spring & Hibernate for Beginners" udemy course. I struggled while trying to import org.springframework.context.support.ClassPathXmlApplicationContext;

Eclipse shows me the error: ClassPathXmlApplicationContext cannot be resolved

The author of the course to which I'm listening is still not involving Maven (and pom.xml) because he is concentrating on "pure" Java and Spring in his course, so please don't direct me to use Maven for organizing the project.

I added all jars from spring-framework-5.0.2.RELEASE-dist to my projects buildpath.

The funny thing is that when i do CTRL+Shift+O Eclipse automatically imports the org.springframework.context.support.ClassPathXmlApplicationContext package, but it shows error in import line (red line under org) and shows an error in my main function on the line where I try to use context as:

ClassPathXmlApplicationContext context = 
        new ClassPathXmlApplicationContext("applicationContext.xml");

Please help.

like image 349
nvkvc Avatar asked Sep 08 '25 01:09

nvkvc


2 Answers

I just want to share that Ш have found a solution to my problem. My execution environment JRE was set to be JAVA SE 10. After I change it to be JAVA SE 1.8 everything started working, and no errors are showing now.

I do it like this:

  1. Right click on your project, then open Properties
  2. Java build path
  3. Click on Add Library
  4. Choose JRE system library
  5. Click on environments and choose JAVA SE 1.8
  6. After that, I removed JAVA SE 10 from my build path and everything becomes right.
like image 149
nvkvc Avatar answered Sep 10 '25 06:09

nvkvc


Delete the module-info.java file in your project, It's only used if you're using Java's built-in module system.

Hope that helps:)

like image 28
Sai Mekala Avatar answered Sep 10 '25 08:09

Sai Mekala