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.
Related
I am getting this error when I try to start the Spring Boot Application:
java: cannot access org.springframework.boot.SpringApplication bad class file: /repository/org/springframework/boot/spring-boot/3.0.1/spring-boot-3.0.1.jar!/org/springframework/boot/SpringApplication.class
class file has wrong version 61.0, should be 55.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
I had a look at the below SO question and it looks like this error happens when the Spring Boot version is 3.0.1. But I dont have that version mentioned in the build.gradle file.
java: cannot access org.springframework.boot.SpringApplication bad class file
here is the build.gradle file portion:
springCloudVersion = '2021.0.3'
springBootPluginVersion = '2.7.6'
sonarQubePluginVersion = '3.3'
gatlingPluginVersion = '3.8.4'
nebulaPublishingPluginVersion = '18.4.0'
nebulaReleasePluginVersion = '16.0.0'
jasyptSpringBootStarterVersion = '3.0.4'
Using Java 11.
I can also see that every time I build the project in IntelliJ, a spring boot 3.0.1 jar and its folder are created under the repository mentioned above ( even if I delete it). I can't see where is that version coming from. Any pointers will be greatly appreciated.
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?
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
I'm working on a java project with spring on eclipse using Maven, and running on a Tomcat server v6.0. Everything was working fine since yesterday morning.
Here his my problem : I'm building my project, I got a build success. Then I start my Tomcat server and got this error :
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:applicationContext- core.xml]
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext-core.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext-core.xml] cannot be opened because it does not exist
I found out similar problem on some website but none of them give me a solution that worked for me.
It seems that eclipse isn't able to find applicationContext-core.xml when I'm doing this :
<import resource="classpath:applicationContext-core.xml" />
However, I do have the needed jar file nad-core-0.0.1-SNAPSHOT.jar in WEB-INF/lib containing applicationContext-core.xml.
I even tried to add it manually to the classpath but I was still having the same problem.
I keep on looking for a solution, when suddendly it work again once after restarting Eclipse and building while Eclipse was still updating indexes and my project was having this strange status Hg status pending instead of default. Surprised by this result I decide to build again my project after restarting Eclipse and I got the error again and I enable to make it work again. It's quite annoying...
This looks to be a really random problem.
Thanks a lot for your help :)
As you've not specified you web application structure. I assume you've a simple web application at hand with the following structures
webapp
WEB-INF/classes/applicationContext.xml
WEB-INF/lib/nad-core-0.0.1-SNAPSHOT.jar/applicationContext-core.xml
Application context.xml refers to the applicationContext-core.xml file using the import tag. I did encounter a similar situation in my web application, here're the check lists that you should go through and may be one of them can apply to your situation.
Check the generated snapshot jar file for the applicationContext-core.xml file and make sure it is in the root directory of the jar. As silly as it sounds, this was the root cause of the issue I faced in my deployment.
Make sure your Maven Pom.xml file is configured to include this XML file from the resources folder. You can use the resource tags in the build phase of Maven to package them within the jar file itself.
You can try removing the import tag from application context.xml file and instead load both of them from Spring's webapplication context itself.
Add a context loader listener class from spring org.springframework.web.context.ContextLoaderListener
Add context-param contextConfigLocation with value classpath:applicationContext-core.xml,classpath:applicationContext.xml. Spring has the ability to dynamically sort out the dependencies before initiating the bean factory.
Hope this check list helps.
I get pretty much the same config, six years later, I got the same error.
I also restart Eclipse, and it solved the issue.
While running the application I was getting the following errors.
java.lang.NoClassDefFoundError: Could not initialize class org.apache.axis2.description.AxisService
AxisService class is in axis2-kernel-1.6.2.jar file. Some of the classes from this jar are working fine without any issues, but some classes are throwing NoClassDefFoundError from this jar file at runtime. AxisService class is present in axis2-kernel-1.6.2.jar, even it throws error.
This is working fine in local machine. But error getting in Oracle r12 server.I have already set the class path for the jar file.
I am Using Java version is 1.6 and Apache axis2.1.6.2.
Had the same issue. I had included only jars that I needed to compile the application.
When I included everything from \axis2-1.6.2\lib\ folder, this exception were gone.
I had a similar problem using Tomcat and Axis2 and after a week finding out the error I realized there was a axis configuration problem. especifically my aplication can't instantiate the class which accedded to persistence layer. I include this parameter line:
<parameter name="ServiceTCCL">composite</parameter>
in services.xml file which is used by axis2 to work.
For more information see the comments in http://wso2.com/node/1131