I am trying to run a spring project in intellij. When I import the code and add the necessary jars, it there is no error during compile time. However, when I run the project, I get the following error
Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: com/company/access/KeyValueAccess
The KeyValueAccess
class is present in the cassandra-access-1.12.0.jar
as highlighted in the image.
I have tried to add jars as modules and also as libraries.
What is the correct way to avoid this runtime
error?
PS: This is the case for only manually added external libraries. The libraries downloaded with maven work just fine.
Edit
The following code generates the exception
@Bean
public KeyValueAccess keyValueAccess() {
return new CassandraAccessDatastax(); //This doesn't matter, the return type itself creates the exception
}
Exception generated is as below:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.worksap.bootcamp.webeditor.config.WebEditorConfig#0' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: com/company/access/KeyValueAccess
I also checked that the jar does it fact have the required class files.
Edit2
I manually ran maven to add the jar files, so I can now find them in ~/.m2/repository
. When I call a class in the jar, it seems to find it but when that class calls another class in the same jar, it gives java.lang.NoClassDefFoundError