I am learning Spring from this tutorial here : https://youtu.be/k0mNw-_zxrc
You can skip to 58.35 minutes as video is pretty long.
In this tutorial, instructor downloads spring dependencies (spring-beans, spring context, spring-core) in version (4.3.9) release.
And then writes this code :
package com.durgasoft.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Test {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Beans obj = (Beans)context.getBean("firstBean");
obj.print();
}
}
When I use: spring-context, spring-beans and spring-core in last version 4.3.9.RELEASE then ApplicationContext import doesn't work. It says "org.springframework.context.ApplicationContext is not accessible ". "org.springframework.context.support.ClassPathXmlApplicationContext is not accessible".
I thought I downloaded wrong jars but the same jars works fine on IntelliJ.
Note : I am not using Maven or Gradle, I am just making a simple Java project like the instructor and I added jar files manually in 'lib' folder in classpath instead of modulepath in eclipse. I am using Eclipse 2023-03 ( for Java ee developers)
And here is the exception when I run it
Exception in thread "main" java.lang.Error: Unresolved Compilation Problems:
ApplicationContext can't be resolved to a type
ClassPathXmlApplicationContext cant be resolved to a type
Any solution ?
Edit : I just noticed that there is " module-info.java" inside of src folder and it has several modules of the jars I added. All of them throws error - " spring-module can't be resolved to a module "
Edit2 : The culprit was wrong syntax in " module-info.java". Deleting it allowed me to access the import. Code compiles and runs fine now.