The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [31] in the generated java file: [H:\eclipseWorkspace\J2EEspace\GlossaryPortal\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\Spring3HibernateApp\org\apache\jsp\WEB_002dINF\views\index_jsp.java]
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:476)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

The below line from the generated java file causing the issue from _jspInit() method

_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();

Previous to this exception, I was facing the below exception

java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config

To resolve this, I have downloaded the following JAR files from the web and placed it in /WEB_INF/lib folder

1) jsp-api-2.0.jar
2) jstl-1.2.jar

But you know, the jsp-api-2.0.jar is now lead to the exception “The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory”.

Solution

We should refer the target runtime in our project, not copy some libraries of an arbitrary servletcontainer make/version into our project. It would make our project incompatible with servletcontainers of a different make and/or version.

As simple, if you are using Tomcat 7 as server, then refer the jsp-api.jar from your Tomcat home directory’s lib folder. Don’t arbitrarily download some container version’s jsp=api file.

The project jar files should compatible with your servlet containers, which is the Tomcat Server that you are using as the Target Runtime.

So

You need to reference a server runtime in your project.

In Eclipse:

1) Choose “Project | Properties | Java Build Path | Libraries Tab”
2) Click “Add Library | Server Runtime | Apache Tomcat 7”
3) Click OK.
4) Clean your project, and build it again (“Project | Clean”, then “Project | Build All”)

That should do it!

Happy Learning 🙂

java.lang.AbstractMethodError: oracle.jdbc.driver.OracleDatabaseMetaData.locatorsUpdateCopy()Z

java.lang.AbstractMethodError: oracle.jdbc.driver.OracleDatabaseMetaData.locatorsUpdateCopy()Z
org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:143)
org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73)
org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2283)
org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2279)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1748)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1788)
org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242)
org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:372)
org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:357)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:589)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)

Solution

Switching to Oracle 10g jdbc driver solved the problem immediately, without any configuration change requirements.

Download link: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html

Remember that Oracle recommends you to use 10 series drivers even if you are connecting to a 8 or 9 series database server!

Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver

I am trying to connection my java web application to the Oracle9i database.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/config/sdnext-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

Solution

Make sure you have the ojdbc14.jar in your run time classpath.

Download the same from http://www.oracle.com/technetwork/database/enterprise-edition/jdbc9201-092698.html

Happy Learning 🙂

nested exception is java.lang.NoClassDefFoundError: org/springframework/transaction/interceptor/TransactionInterceptor


SEVERE: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/config/sdnext-servlet.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/transaction/interceptor/TransactionInterceptor
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/springframework/transaction/interceptor/TransactionInterceptor
at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser$AopAutoProxyConfigurer.configureAutoProxyCreator(AnnotationDrivenBeanDefinitionParser.java:126)
at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser.parse(AnnotationDrivenBeanDefinitionParser.java:84)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1435)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1425)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
... 35 more

Oct 12, 2014 11:02:51 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/config/sdnext-servlet.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/transaction/interceptor/TransactionInterceptor
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/springframework/transaction/interceptor/TransactionInterceptor
at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser$AopAutoProxyConfigurer.configureAutoProxyCreator(AnnotationDrivenBeanDefinitionParser.java:126)
at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser.parse(AnnotationDrivenBeanDefinitionParser.java:84)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1435)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1425)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
... 35 more

Solution

First, You need to check your runtime classpath (i.e. WEB-INF/lib) for spring-tx-…jar

Next, add aopalliance-1.0.jar or com.springsource.org.aopalliance-1.0.0.jar in the classpath solves the problem.

https://www.google.co.in/#q=download+latest+aopalliance+jar

Happy Learning 🙂

Cannot find the declaration of element ‘beans’.


org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from ServletContext resource [/WEB-INF/config/sdnext-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 64; cvc-elt.1: Cannot find the declaration of element 'beans'.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1284)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1197)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5229)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5516)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 64; cvc-elt.1: Cannot find the declaration of element 'beans'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
... 29 more

Solution

First make sure that your spring library version matches with the XSD version.

For example, here I have used the spring version 3.2.0, so I have used spring XSD of 3.2 version as shown below


<beans xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemalocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

So now, the XSD version and the spring version both matches. Still the issue persist? Then, we need to open our eyes to find any typo error. So from the above ‘beans’ xsd definition, there is a typo error

The problem is with my definition of xsi:schemalocation the typo is with the L It is supposed to be capital, only then would it recognize the tag.

Change the xsi:schemalocation to xsi:schemaLocation

<beans xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd" >

Happy Learning 🙂

java.lang.NoClassDefFoundError: Lorg/apache/commons/logging/Log;

Caused by: java.lang.NoClassDefFoundError: Lorg/apache/commons/logging/Log;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredFields(Unknown Source)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:270)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:139)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:403)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:879)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.Log
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
... 20 more

Solution

Adding the commons-logging.jar to the class path will solve the problem.

Download the same from http://commons.apache.org/proper/commons-logging/download_logging.cgi

Happy Learning 🙂

SEVERE: Servlet /Spring3HibernateApp threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

I was working on the Spring MVC example. When I deployed my Spring web application into the Apache Tomcat 7 server, I end up with the following exception


Oct 12, 2014 8:24:01 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /Spring3HibernateApp threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:530)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:512)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:139)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5229)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5516)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Solution

ClassNotFoundException should always makes you to think “JAR is missing”. That is, the eclipse could not able to locate the class file ‘DispatcherServlet” here. The ClassNotFoundException clearly indicates that you are missing org.springframework.web.servlet classes.

So make sure the Spring MVC JAR files is available in the classpath. The Spring JARs and all their dependencies should be in your /WEB-INF/lib.

Add all JAR files in the Project build path, which is, Right-click on Project -> Properties -> Java Build Path -> Libraries. Add all external JARS as like either user library or web app libraries. Click on “Add External JARs” to add all the JAR files.

Even after this, if the exception occurs, try the below instructions

1) Project Properties -> Deployment Assembly
2) Add -> Java Build Path Entries
3) You should now see the list of libraries on your build path that you can specify for inclusion into your finished WAR.
4) Select the ones you want and hit Finish.

Happy Learning 🙂

Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core”

When you get this error in eclipse or anywhere, make sure that you have the Apache’s standard taglib JARs, an implementation of the JSP Standard Tag Library (JSTL) specification,

Goto the following link

http://tomcat.apache.org/taglibs/standard/

and navigate to the

http://tomcat.apache.org/download-taglibs.cgi

and download the below JAR

taglibs-standard-impl-1.2.1.jar

Thanks!! 🙂

Autowiring in Spring Framework

AutoWiring by Name (autowire=”byName“)
======================================

MiniTriangle.java

package com.saravanansivaji.spring;

public class MiniTriangle {

private Point pointA;
private Point pointB;
private Point pointC;

public Point getPointA() {
return pointA;
}
public void setPointA(Point pointA) {
this.pointA = pointA;
}
public Point getPointB() {
return pointB;
}
public void setPointB(Point pointB) {
this.pointB = pointB;
}
public Point getPointC() {
return pointC;
}
public void setPointC(Point pointC) {
this.pointC = pointC;
}

public void draw() {
System.out.println("Mini-Triangle drawn with the following points using AutoWire:");
System.out.println("("+getPointA().getX()+","+getPointA().getY()+")");
System.out.println("("+getPointB().getX()+","+getPointB().getY()+")");
System.out.println("("+getPointC().getX()+","+getPointC().getY()+")");

}
}

spring.xml

<!-- MINI-SQUARE AREA Begins -->
<bean id="miniTriangle" class="com.saravanansivaji.spring.MiniTriangle" autowire="byName"/>

<bean id="pointA" class="com.saravanansivaji.spring.Point">
<property name="X" value="10"></property>
<property name="Y" value="10"></property>
</bean>
<bean id="pointB" class="com.saravanansivaji.spring.Point">
<property name="X" value="10"></property>
<property name="Y" value="20"></property>
</bean>
<bean id="pointC" class="com.saravanansivaji.spring.Point">
<property name="X" value="10"></property>
<property name="Y" value="40"></property>
</bean>

<!-- MINI-SQUARE AREA Ends-->

From application file

ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
MiniTriangle miniTriangle = (MiniTriangle) context.getBean("miniTriangle");
miniTriangle.draw();

Upon execution, the output is

Mini-Triangle drawn with the following points using AutoWire:
(10,10)
(10,20)
(10,40)

So Spring does this autowiring “byName”, when the member variable names of the bean class matches with any of the bean id’s name in the spring configuration file. Spring looks for a bean with the same name as the property that needs to be autowired.

Bean id names should be unique in the spring configuration xml document.

AutoWiring by Type (autowire=”byType“)
======================================

Let I execute the above same code with little modification in the spring configuration file document,

Just changed the attribute autowire to “byType”

spring.xml

<!-- MINI-SQUARE AREA Begins -->
<bean id="miniTriangle" class="com.saravanansivaji.spring.MiniTriangle" autowire="byType"/>

<bean id="pointA" class="com.saravanansivaji.spring.Point">
<property name="X" value="10"></property>
<property name="Y" value="10"></property>
</bean>
<bean id="pointB" class="com.saravanansivaji.spring.Point">
<property name="X" value="10"></property>
<property name="Y" value="20"></property>
</bean>
<bean id="pointC" class="com.saravanansivaji.spring.Point">
<property name="X" value="10"></property>
<property name="Y" value="40"></property>
</bean>

<!-- MINI-SQUARE AREA Ends-->

When we execute, we get the below spring exception,

Exception in thread “main” org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘miniTriangle’ defined in class path resource [spring.xml]: Unsatisfied dependency expressed through bean property

‘pointA’: : No unique bean of type [com.saravanansivaji.spring.Point] is defined: expected single matching bean but found 3: [pointA, pointB, pointC]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:

No unique bean of type [com.saravanansivaji.spring.Point] is defined: expected single matching bean but found 3: [pointA, pointB, pointC]

Autowiring by Type – allows a property to be autowired if exactly one bean of the property type exists in the container. If more than one exists, a fatal exception is thrown, which indicates that you may not use byType autowiring for

that bean. If there are no matching beans, nothing happens; the property is not set.

AutoWiring by Constructor (autowire=”constructor“)
==================================================

Slightly modifying my bean class, removing all the setters as follows

MiniTriangle.java

package com.saravanansivaji.spring;

public class MiniTriangle {

private Point pointA;
private Point pointB;
private Point pointC;

public MiniTriangle(Point pointA, Point pointB, Point pointC) {
this.pointA = pointA;
this.pointB = pointB;
this.pointC = pointC;
}

public Point getPointA() {
return pointA;
}

public Point getPointB() {
return pointB;
}

public Point getPointC() {
return pointC;
}

public void draw() {
System.out.println("Mini-Triangle drawn with the following points using AutoWire-constructor:");
System.out.println("("+getPointA().getX()+","+getPointA().getY()+")");
System.out.println("("+getPointB().getX()+","+getPointB().getY()+")");
System.out.println("("+getPointC().getX()+","+getPointC().getY()+")");
}
}

spring.xml

<!-- MINI-SQUARE AREA Begins -->
<bean id="miniTriangle" class="com.saravanansivaji.spring.MiniTriangle" autowire="constructor"/>

<bean id="pointA" class="com.saravanansivaji.spring.Point">
<property name="X" value="10"></property>
<property name="Y" value="10"></property>
</bean>
<bean id="pointB" class="com.saravanansivaji.spring.Point">
<property name="X" value="10"></property>
<property name="Y" value="20"></property>
</bean>
<bean id="pointC" class="com.saravanansivaji.spring.Point">
<property name="X" value="10"></property>
<property name="Y" value="40"></property>
</bean>
<!-- MINI-SQUARE AREA Ends-->

Output:

Mini-Triangle drawn with the following points using AutoWire-constructor:
(10,10)
(10,20)
(10,40)

Happy Coding 😀

idref in Spring? What is the purpose of idref tag in Spring?

Today I took more time to understand the purpose of tag in Spring. I didn’t expect this tag creates more confusion among developers as I see in Google there were many post and discussions occurred against the tag.

Not only me, many struggled with the below spring error message seems 😀

“Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘square’ defined in class path resource [spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type ‘java.lang.String’ to required type ‘com.saravanansivaji.spring.Point’ for property ‘pointD’; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.saravanansivaji.spring.Point] for property ‘pointD’: no matching editors or conversion strategy found”

It is a simple concept actually

When I got this error?

I have a class called ‘Square.java‘, with one attribute, “pointD”


package com.saravanansivaji.spring;

public class Square {
private Point pointD;

//Getters and Setters for pointD defined
}

package com.saravanansivaji.spring;

public class Point {
private int X;
private int Y;

public int getX() {
return X;
}
public void setX(int x) {
X = x;
}
public int getY() {
return Y;
}
public void setY(int y) {
Y = y;
}
}

The below is my spring configuration file

<bean id="square" class="com.saravanansivaji.spring.Square">
<property name="pointD">
<idref bean="squarePointD"/>
</property>
</bean>

<bean id="squarePointD" class="com.saravanansivaji.spring.Point">
<property name="X" value="20"></property>
<property name="Y" value="40"></property>
</bean>

The above gives the following error

Cannot convert value of type [java.lang.String] to required type [com.saravanansivaji.spring.Point] for property ‘pointD’: no matching editors or conversion strategy found

After some 1.5 hours of struggle, I got to understand that,

the below one,

<property name="pointD">
<idref bean="squarePointD"/>
</property>

is equals to the below one

<property name="pointD">
<value>squarePointD</value>
</property>

So why this error occurs?

The purpose of idref is, it is used to pass the name (identifier) of a bean to the calling class. I didn’t understand this and I see many didn’t understand this immediately.

In my example, Square is the calling class, with a attribute “pointD” of type com.saravanansivaji.spring.Point. But idref has the capability only to pass a bean name (string identifier – type “java.lang.String”) to the calling class. So here I am trying to assign the “squarePointD” of type java.lang.String as value to the attribute ‘pointD’ which is of type com.saravanansivaji.spring.Point.

The above code never works. So I introduced a new String property called “name” in the “Square” class. And the value to this property will be assigned by the attribute. So is that the only purpose you may have question? The ultimate purpose of idref tag is, the idref tag allows the container to validate at deployment time that the referenced, named bean actually exists.

Here is the final code snippets

package com.saravanansivaji.spring;

public class Square {
private Point pointD;
private String name;

//Getters and Setters
}

The below is my spring configuration file now with little changes

<bean id="square" class="com.saravanansivaji.spring.Square">
<property name="pointD">
<ref bean="squarePointD"/> <!-- only ref attribute works here, not the idref attribute -->
</property>

<property name="name"> <!-- assigning the name of a bean correctly to a matching property "name" of type 'java.lang.String' in Square class -->
<idref bean="squarePointD"/>
<!-- idref validates the existence of a bean with name "squarePointD".
If bean exist, it will pass the bean name as string value to the caller
If not exist, throws exception
-->
</property>
</bean>

<bean id="squarePointD" class="com.saravanansivaji.spring.Point">
<property name="X" value="20"></property>
<property name="Y" value="40"></property>
</bean>