NoClassDefFoundError Using Hibernate - java

I'm using Spring 3.1.1.RELEASE and Hibernate 4.1.10.FINAL in a Building Block on Blackboard Learn and getting the following exception:
java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.PropertyContainer
This seems to be a classpath issue, and so I did some digging and added the suggested libraries from this post but the same error occurs.
So my classpath now contains the necessary dependencies, but I am still getting the exception. What are some additional points I can look at to identify and resolve this issue?
Edit: I've verified the jboss-logging JAR is in my classpath.
Edit: Requested Stack Trace: https://gist.github.com/whargrove/79cbc9c5bd65217e3da3
After restarting Tomcat and re-deploying my WAR the following exceptions are observed in the Tomcat logs:
java.security.AccessControlException: access denied ("java.util.PropertyPermission" "jboss.i18n.generate-proxies" "write")
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/config/spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.PropertyContainer
(Full stack trace available in gist link above.)

The message
java.lang.NoClassDefFoundError: Could not initialize class SomeClass
means that the JVM has already tried and failed to perform static initialization on the class SomeClass. There may well be another error which happened earlier on when the JVM tried to load the class the first time.
Taking a look at the source of the PropertyContainer class, the only static intialization is a static initializer that sets a system property, and a line that initializes a logger for the class. Setting a system property will should not cause a problem, so my guess is that the logger class used is missing from your classpath.
The logger class used is org.jboss.logging.Logger. A quick Google for this class suggested a jar named jboss-logging.jar. Try getting a copy of that and adding it to your classpath.
(Incidentally, if you can't find a previous error before the 'Could not initialize class' error, that may well be because the missing JAR affects logging. Logging is something applications tend to assume is always working and can be used everywhere. The exception you are seeing might have been thrown from within a finally block that tried to do some logging when the corresponding try block also tried to do some logging but threw an exception. An exception thrown from within a finally block replaces any exception that had previously been thrown.)
EDIT in response to the stacktrace: I can now see that I was wrong about setting a system property not being the problem! I don't know the first thing about Blackboard Learn, but it is possible that it or something else has tightened up the security in your application and hence caused the above problem.
It does however confirm my belief that the real cause of the problem was before the Could not initialize class message.

Related

Holders.config is null during grails run-war

Recently did a log4j upgrade on grails 2.5.4 application. Following dependencies pertaining to v2.17.1 have been added:
log4j-api
log4j-core
log4j-1.2-api
log4j-slf4j-impl
I've excluded the following dependencies from the global level:
log4j
grails-plugin-log4j
jcl-over-slf4j
The application boots up without any issues on doing grails run-app. But when I try to run the war by grails run-war or deploy the war using tomcat, I keep getting:
Error creating bean with name 'grailsApplication' defined in ServletContext
...
Caused by: java.lang.ExceptionInInitializerError
...
Caused by: java.lang.NullPointerException: Cannot get property 'xyz' on null object
This null object is Holders.config
This issue occurs during static property initialization. The class looks like:
class Test {
public static Logger log = LoggerFactory.getLogger(this)
private static final String SOURCE_URL = Holders.config.xyz.abc
...
}
Another class had the same issue during the initialization of variable using Holders.config in static block.
Strangely, this issue is only for classes under grails-app/utils folder because I've another class under src/groovy where its variables are defined in a similar way but there's no issue with it during the war file execution.
There's no change in code except for the dependencies added/removed as mentioned above.
I also tried using applicationContext.getBean('grailsApplication).config.xyz.abc but it said Could not find ApplicationContext, configure Grails correctly first.
Can someone please suggest what could be the root cause or guide how I can fix or maybe initialize these static values.

java.lang.NoSuchFieldError: com/fasterxml/jackson/annotation/JsonInclude$Include.USE_DEFAULTS

I am using spring 5.3.7
and when I start my application, it returns the error below:
Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]:
Constructor threw exception; nested exception is java.lang.NoSuchFieldError:
com/fasterxml/jackson/annotation/JsonInclude$Include.USE_DEFAULTS
I am using jackson-annotations-2.10.3.jar which implements the USE_DEFAULTS Enum.
I hope some one can help me.
I am not sure, but you should once check for the annotations like #Service, #Controller, #Respository, there are chances that you have missed any one of the annotations. just check it carefully, it might help you out.
To deal with this error, we have to clear all .class files and recompile to ensure that all files are up to date.
If this error still exists at runtime, it may be that the dependency referenced at compile time is different from the runtime version. Here, it is necessary to check whether the various paths and versions are wrong.
Maven projects generally execute mvn clean.
Hope your problem can be solved
Try cleaning your old build and rebuild your project, atleast it works for me!

ConflictingBeanDefinitionException even after deleting a class

I am developing a simple maven + spring application and i am getting the following error. It says two of my classes have a conflict. so i deleted the second class but i am still getting the same error. I tried restarting the server but it still says my class exists. Can somebody help?
Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.nibm.config.RootConfig]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'employeeController' for bean class [com.nibm.hibernate.controller.EmployeeController] conflicts with existing, non-compatible bean definition of same name and class [com.nibm.controller.EmployeeController]
I was able to solve a similar problem by using IntelliJ's function "Rebuild".
The reason was an orphan .class file after the corresponding .java file had already been deleted.
You get the exception because you have two spring beans of the same class.
This exception is thrown by
org.springframework.context.annotation.ClassPathBeanDefinitionScanner#isCompatible
And looking at that implementation it looks as if you create a bean of type EmployeeController in your RootConfig and additionally by ComponentScan.
To fix the problem remove the bean from the RootConfig or change your ComponentScan, so this bean is not found by it.
You can set a breakpoint in the constructor of EmployeeController. From the stack you can get more information about how and why the bean is created.
I faced the same problem and it was because class with same name exist at two locations as mentioned in the Exception itself which are conflicting and after removing one issue got fixed.
I was getting this same ConflictingBeanDefinitionException..."conflicts with existing, non-compatible bean definition of same name and class" when running JUnit tests with #RunWith(SpringRunner.class)/ #SpringBootTest from inside Intellij.
Execution via gradle:build of the same tests were running fine.
This began to happen after I had refactored the packaging of several #Components which lead me to believe something was holding a reference to the class under it's previous package name.
No amount of gradle build/clean would seem to clear it.
Doing a Build -> Rebuild Project in IntelliJ was what cleared this issue for me.

JSP not importing second class

This should be a very easy question but I am not able to get this fixed. I have 2 import statements and in Netbeans it does not show any error but when I run the project, I am getting a ClassnotFoundDef error
<%# page import="mastertables.BranchMaster, mastertables.CreateBranchMaster"%>
both the classes are in the same package. The error is
javax.servlet.ServletException: java.lang.NoClassDefFoundError:org/hibernate/HibernateException
Please help, I am stuck on this small thing.
Thanks,
Abhijeet.
The application server is not able to retrieve the org.hibernate.HibernateException in the classpath. In this case i think you actually have the hibernate jars in your classpath, but the application server is complaining about not being able to find its definition.
Think about it: the most obvious exception for a missing dependency would be a ClassNotFoundExeption.
You are not getting this one, and you are also getting problems on instantiating an hibernate exception. Who would throw an hibernate exception if not the hibernate library itself.
So some part of hibernate is already loaded in the classpath, but not this specific class.
In my experience i'd check for libraries version conflicts/mismatch. Check the version of all the hibernate jars and dependencies.

Class path resource not found randomly

We have integrated Spring with Hibernate and Struts2 in Eclipse and have been getting these errors when running the build:
14-Oct-2011 10:37:27 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [Test.hbm.xml] cannot be opened because it does not exist
...
Caused by: java.io.FileNotFoundException: class path resource [Test.hbm.xml] cannot be opened because it does not exist
...
Our mapping in applicationContext.xml is:
<property name="mappingResources" value="Test.hbm.xml" />
Test.hbm.xml is in /build/classes, and we have tried putting it in /WEB-INF, /src, and even created a new source folder called /hibernate and dumped it in and it worked on only a few machines.
The first time we wrote it, it showed this error. And then we copied the exact same code into a new project, it suddenly worked. On some machines, it works; on others, it shows this error.
Does anyone know what could be wrong? Let me know if any other information is needed.
Thanks so much.
That's not a build-time error. It's a run-time one. Intermittent failures of that sort indicate a problem with your build, though. As a classpath resource, Test.hbm.xml must be in a classpath location when you run your app. Where exactly that is depends on how you're running it, but /WEB-INF will never work for a webapp, and a random /hibernate folder is unlikely to work, too, unless you've done some custom configuration to make that a classpath resource or make it build to one. For a more definitive answer, you'll need to provide more detail about what you're running and how you're building it.

Categories

Resources