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

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?

Related

FindException in connecting with Mysql database

I'm using ubuntu system, and using Mysql 8.0. I trying to connect database with jdbc class but having an error,although I added the mysql-connector.jar file,
The error I mentioned below,
-->Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: /home/surya/eclipse-workspace/Advancedjava/bin
Caused by: java.lang.module.InvalidModuleDescriptorException:
mysql_conntn.class found in top-level directory (unnamed package not allowed in module)
You have a module-info.java in your project making it a modular Java project. However, you also have a class (mysql_conntn) in the default (unnamed) package, and this is not allowed in a modular project.
Either you need to make your project non-modular by removing module-info.java, or you need to move the class mysql_conntn to a named package.

Spring Error occurred during initialization of boot layer In Eclipse

when I download the files of Spring and added them to eclipse I get this error for the "Hello World" project;
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Program
Files\eclipse\spring-framework-5.1.9.RELEASE\libs\spring-context-indexer-5.1.9.RELEASE-sources.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class
org.springframework.context.index.processor.CandidateComponentsIndexer not in module
follow those steps to solve the problem;
1- download the lastes version of Spring in her (in my case it was, "5.2.0.RELEASE/ 30-Sep-2019 09:06") chose the spring-X.x.x.RELEASE-dist.zip.
2- Unzip the files.
3- in eclipse add extranl jars Steps In the Libs folder, don't take the ones with spring-xxx-X.x.x.RELEASE-sources.
4- done.

Java spring error: It is not working even i đid exactly everything the teacher said

package springdemo4;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HelloSpringApp {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Coach theCoach = context.getBean("myCoach",Coach.class);
System.out.println(theCoach.getDailyFortune());
System.out.println(theCoach.getDailyWorkout());
context.close();
}
}
I ran it, then it said:
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\ngoch\eclipse-workspace\springdemo4\libs\spring-context-indexer-5.1.9.RELEASE-sources.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.springframework.context.index.processor.CandidateComponentsIndexer not in module
Please,help
I had the same issue with Eclipse IDE. I mistakenly added the spring jar files under Modulepath. It should be under Classpath (Properties > Java Build Path > Classpath > addJARs ).
You need to add the libraries under classpath and not under modulepath.
Spring libraries should be under classpath
Below steps worked for me:
Go to project properties -> Libraries -> add your user libraries under classpath. Remove your librarey reference from Modulepath.
Project properties from eclipse

Error occurred during initialization of boot layer spring framework

When I am running my code the Console shows the following error
"Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for
C:\Users\Ankit
Singh\Downloads\spring-framework-5.1.9.RELEASE\libs\spring-context-indexer-5.1.9.RELEASE-sources.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider
class
org.springframework.context.index.processor.CandidateComponentsIndexer
not in module
Default Package delete.
Reinstalled Spring library
Two different way to call beans
Can someone suggested whats wrong in my system??
You might use a default package, right? I have had the same error as you...
Listen, dude, you can try to click: your project name-properties-java build path, move your external jar(s) from module-path to classpath. Then, you can run the code again.

Why is the AbstractApplicationContext throwing NoClassDefFoundError for LogFactory?

I am using the newest STS, just updated:\
Version: 2.9.0.RELEASE
Build Id: 201203011000
I have downloaded spring-framework-3.1.1.RELEASE into a directory.
I created a new Spring project. If the main() contains only a System.out.println() it's working fine with no problem.
I made a lib/ dir in my project and imported all the libs from the Spring Framework. I also imported commons-logging-1.1.1.jar
But if I add:
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
When I run the app it throws: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
I printed out the class path from main():
System.out.println(System.getProperty("java.class.path"));
And I can see the commons-logging-1.1.1.jar on it since I added it.
If I make in main(): org.apache.commons.logging.LogFactory lf; it has no problem at all, code completion is working fine also.
What should I check?
OK, my bad.
I did not import the Spring jars into the project, just added them as User library. As I imported them and added explicitly to the class path everything just went fine.

Categories