Exceptions encountered during Development
Miscellaneous Exceptions:-
You might encounter various exceptions while developing a Project with Spring and Hibernate.
I have depicted few of them here and their solutions:-
1.
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/collections/map/LRUMap
Solution:-
Use commons-collections.jar
2.
SEVERE: Servlet.service() for servlet spring threw exception
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'org.springframework.transaction.interceptor.TransactionInterceptor#0' must be of type [org.aopalliance.aop.Advice], but was actually of type [org.springframework.transaction.interceptor.TransactionInterceptor]
Solution:-
It might be due to a classloading issue.
Specifically, you either have two copies of Spring being loaded by two different classloaders, or two copies of aop-alliance (or aopalliance-alpha1.jar ) being loaded by two different classloaders.
3.
SEVERE: Servlet.service() for servlet spring threw exception
java.lang.ClassNotFoundException: antlr.ANTLRException
OR, in eclipse browser you might read it as:
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is
java.lang.NoClassDefFoundError: antlr/ANTLRException
Solution:-
This exception might be in lack of 'antlr.jar'. Download it and add to your class path of project.
4.
org.hibernate.hql.ast.QuerySyntaxException: contact.form.contact is not mapped [ from contact.form.contact]
Solution:-
Mind the name of the java class which is mapped to a table in database.It is case sensitive. For example in above case, the name of java class is Contact not contact.
5. While defining the security xml files in web.xml file, you might get this exception:
SEVERE: Servlet.service() for servlet spring threw exception
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:251)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Solution:-
It might be because of the missing the entry of the following into we.xml file:
6. I get the following exception:
SEVERE: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]
Offending resource: ServletContext resource [/WEB-INF/contact-security.xml]
Solution:-
This could be in lack of the "spring-security-acl-xxx.jar"
OR
Even sometimes even if you add the jars into build path of Eclipse, it might not get added. Therefore, copy these following Jar files directly into lib folder of your project:
- pring-security-core
- spring-security-ldap
- spring-security-config
- spring-security-web
- spring-security-taglibs
- spring-security-acl
Comments