How to fix error java.lang.module.FindException in Spring (java11)

Viewed 149

I have been reading posts in StackOverflow for almost 1 hour and no solutions worked for me. I am doing a beginner Spring Course using Eclipse and JDK11. And I am having the following error in the terminal:

An error occurred during initialization of boot layer
java.lang.module.FindException: Module proyectoSpringUno not found

this is my java file:

package es.pildoras.IoC;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UsoEmpleados {

    public static void main(String[] args) {    
        
        ClassPathXmlApplicationContext contexto = new ClassPathXmlApplicationContext("applicationContext.xml");
        
        Empleados Juan = contexto.getBean("miEmpleado",Empleados.class);
        
        System.out.println(Juan.getTareas());
        
        contexto.close();
    }

}

I have an error on the import that says:

The type org.springframework.context.support.ClassPathXmlApplicationContext is not accessible

I know that this error happens because I am using the java module system and if I use java 8, all these issues will disappear, but I am not interested in that solution since I want to learn how to use Spring with newer Java JDKs.

At the moment, I have all my libs added into the Classpath but not into the Modulepath.

Solution I tried:

Adding the libs to the modulepath. Result: this doesn't work. When I add the libs to the modulepath, Eclipse deletes the libs from the classpath ( probably to avoid duplicates). Now I don't have any issues in the module-info (eclipse inserted automodules) or in the import, but when I launch my app, I have the following error:

Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\Stephane\Desktop\curso Spring\ProyectoSpringUno\libs\spring-context-indexer-5.3.6-sources.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.springframework.context.index.processor.CandidateComponentsIndexer not in module

this is the module info:

module ProyectoSpringUno {  
    exports es.pildoras.IoC;
    requires spring.context; // this is automaticly added by eclipse when i add libs to the modulepath
}

Resuming

  • When I add my dependencies to the modulepath, Eclipse don't work because he wants it in the classpath.
  • When I add my dependencies to the classpath, eclipse say I need to move some dependencies to the modulepath or the module-info will not work.
  • And eclipse don't let me add them to both modulepath and classpath because they are duplicates.

Any idea on how to fix this?

0 Answers
Related