I am working on Maven and I get error as shown below. I tried checking deployment assembly and build path but I am not getting any hint on what the system is complaining about. I also made sure I cleaned tomcat directory and cleaned the project. I would appreciate any help on it
Jan 20, 2020 12:11:13 PM org.apache.catalina.core.StandardWrapperValve
invoke SEVERE: Servlet.service() for servlet [cas] in context with
path [/URL] threw exception [Request processing failed; nested
exception is
org.springframework.webflow.execution.ActionExecutionException:
Exception thrown executing
org.springframework.webflow.action.ViewFactoryActionAdapter#2def1006
in state 'viewServiceErrorView' of flow 'login' -- action execution
attributes were 'map[[empty]]'] with root cause
java.lang.ClassNotFoundException: org.opensaml.SAMLStatement at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1139)
at java.lang.Class.getDeclaredConstructors0(Native Method) at
java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) at
java.lang.Class.getConstructor0(Class.java:3075) at
java.lang.Class.getDeclaredConstructor(Class.java:2178) at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.
As the system was complaining I was missing opensaml jar.
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml</artifactId>
<version>1.1</version>
</dependency>
System was unable to download the jar from maven repo. I manually updated the jar in my local and it worked fine.
This question already has answers here:
java.lang.ClassNotFoundException: HttpServletRequest
(16 answers)
Closed 3 years ago.
I tried to create/run a basic JSP and ran into the following error. I saw that other people have had similar problems, however, I haven't been able to find (or properly implement) a solution to the problem at hand yet. Any help would be appreciated!
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SimpleServletProject]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:816)
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(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SimpleServletProject]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: java.lang.NoClassDefFoundError: HttpServletRequest
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
at java.lang.Class.getDeclaredMethods(Class.java:1967)
at org.apache.catalina.util.Introspection.getDeclaredMethods(Introspection.java:127)
at org.apache.catalina.startup.WebAnnotationSet.loadMethodsAnnotation(WebAnnotationSet.java:287)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:140)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:415)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:892)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)
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:5380)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.lang.ClassNotFoundException: HttpServletRequest
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
... 20 more
Jan 22, 2015 9:04:06 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:739)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
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(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:816)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Jan 22, 2015 9:04:06 PM org.apache.catalina.startup.Catalina start
SEVERE: The required Server component failed to start so Tomcat is unable to start.
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:739)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 11 more
Jan 22, 2015 9:04:06 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
Jan 22, 2015 9:04:06 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
Jan 22, 2015 9:04:06 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jan 22, 2015 9:04:06 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8080"]
Jan 22, 2015 9:04:06 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-8009"]
I faced similar issue and it was caused because I had written WebServlet Path in the .java file as well as in the web.xml . Removing it from any one location works fine for me.
In the .java file
#WebServlet("/index1.jsp")
and in web.xml
<servlet>
<servlet-name>Logout</servlet-name>
<servlet-class>tpc.Logout</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Logout</servlet-name>
<url-pattern>/index1.jsp</url-pattern>
</servlet-mapping>
You must have packaged the servlet-api.jar along with the other libraries in your war file. You can verify this by opening up your war file and navigating to the WEB-INF/lib folder.
Ideally, you should not provide the servlet-api jar. The container, in your case Tomcat, is responsible for providing it at deploy time to your application. If you try to provide it as well, then issues arise due to version mismatch etc. Best practise is to just avoid packaging it. Remove it from the WEB-INF/lib.
Additional Information
If you are using maven for your packaging, then simply add the provided tag with the dependency and maven will make sure not to package it in the final war file. Something like
<dependency>
<artifact>..
<group> ...
<version> ...
<scope>provided</scope>
</<dependency>
Your webapp has servletcontainer specific libraries like servlet-api.jar file in its /WEB-INF/lib. This is not right.
Remove them all.
The /WEB-INF/lib should contain only the libraries specific to the webapp, not to the servletcontainer. The servletcontainer (like Tomcat) is the one who should already provide the servletcontainer specific libraries.
If you supply libraries from an arbitrary servletcontainer of a different make/version, you'll run into this kind of problems because your webapp wouldn't be able to run on a servletcontainer of a different make/version than where those libraries are originated from.
How to solve:
In Eclipse
Right click on the project in eclipse Properties -> Java Build Path -> Add library -> Server Runtime Library -> Apache Tomcat
Im Maven Project:-
add follwing line in pom.xml file
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${default.javax.servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${default.javax.servlet.jsp.version}</version>
<scope>provided</scope>
</dependency>
Delete the project named Servers (or Servers1, Servers2 which contains your server.xml), find it in Package Explorer(workspace)
Remove server from Eclipse :
Go to Window > Preferences > Server > Runtime Environment, here remove the server your are using from eclipse and add it again(doing this will create a new Server project folder in Eclipse) ,
Remove server from Project :
Also remove the server in your project(Build path > configuration path > Java Build path) and add again.
now you got a fresh Server project which will not have Multiple Context on its server.xml, only deleting duplicate path in server.xml solved the existing issue but still server dint start, by doing this Server started(Apache Tomcat v7) and worked normal
And I don't know whether this is good practice or not, I am a starter in programming.
I try with http servlet and I find this issue when I write duplicated #WebServlet ,I encountered with this issue.After I remove or change #WebServlet value it is working.
1.Class
#WebServlet("/display")
public class MyFirst extends HttpServlet {
2.Class
#WebServlet("/display")
public class MySecond extends HttpServlet {
check if you JAVA_HOME is set to 1.7 or below. because tomcat 7 is not compatible with jdk 1.8
This worked for me
This is what worked for me:
1) add commons-logging.jar to the WEB-INF/lib folder
2) Add this jar as a maven dependency, e.g. add this to the pom.xml:
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
3) Maven install
4) Run the server.
Hope it helps.
I faced similar issue with similar logs. I was using JDK 1.6 with apache tomcat 7. Setting java_home to 1.7 resolved the issue.
Some time this problem occur due to incompatible java version and tomcat version.Choose the compatible version of both.
Faced the same issue. Changed the JRE to the correct 1.8 version and do a maven clean and build resolve the issue. You may need to change the Project Facet and verify the correct path.
download commons-logging-1.1.1.jar.
Go to Your project,build path, configure build path, java build path.
Add external jars.. add commons-logging-1.1.1.jar
click on apply, ok
Go to project, properties, Deployment Assembly, Click on add,Java build path entries, next, select commons logging jar,ok,,apply, ok..
Delete server,clean ur proejct, add server, Run your project.
Added AWS dependency and had this error. When I remove it from pom the error is gone. Probably you might have the same situation.
This issue might also be caused by a broken Maven repository.
I observe the SEVERE: A child container failed during start message from time to time when working with Eclipse. My Eclipse workspace has several projects. Some of the projects have common external dependencies. If Maven repository is empty (or I add new dependencies into pom.xml files), Eclipse starts downloading libraries specified in pom.xml into Maven repository. And Eclipse does that in parallel for several projects in the workspace. It might happen that several Eclipse threads would be downloading the same file simultaneously into the same place in Maven repository. As a result, this file becomes corrupted.
So, this is how you could resolve the issue.
Close your Eclipse.
If you know which specific jar-file is broken in Maven repository, then delete that file.
If you do not know which file is broken in Maven repository, then delete the whole repository (rm -rf $HOME/.m2).
For each project, run mvn package in the command line. It is important to run the command for each project one-by-one, not in parallel; thus, you ensure that only one instance of Maven runs each time.
Open your Eclipse.
I have observed a similar issue in my project. The issue was solved when the jar with the missing class definition was pasted into the lib directory of tomcat.
I added maven set up to my eclipse project and I am able to see the lib in my target folder,
I referred the AWS SES docs to send mail using API . I wont see any complation error but when I try to send mail usig AWS SES API I am getting class not found exception .
java.lang.ClassNotFoundException: org.apache.http.pool.ConnPoolControl
After searching on google I added jars (both with mavan and Java build path ) ,Both of the ways doesnt work out.
I am unable to find out the exact problem .
my maven code includes .
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.8.9.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-hal-client-java</artifactId>
<version>1.1.1</version>
</dependency>
I can able import all class specified in doc,but whenever i call email sending method I getting class not found exception .
I have
1.Eclipse Helios
2. Spring-hibernate project
3.Maven 2
and I have access and secret key for AWS set up
Please some one help me out .
I encountered the following error:
Sep 01, 2014 4:18:30 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [spring] in context with path [/peer] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/pool/ConnPoolControl] with root cause
java.lang.ClassNotFoundException: org.apache.http.pool.ConnPoolControl
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2888)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1172)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
at com.amazonaws.http.ConnectionManagerFactory.createPoolingClientConnManager(ConnectionManagerFactory.java:29)
at com.amazonaws.http.HttpClientFactory.createHttpClient(HttpClientFactory.java:97)
at com.amazonaws.http.AmazonHttpClient.<init>(AmazonHttpClient.java:181)
at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:119)
at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:103)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.<init>(AmazonSimpleEmailServiceClient.java:142)
at com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.<init>(AmazonSimpleEmailServiceClient.java:123)
i tried to compile and run my application code but i get a class not found exception i will print the stack trace i hope there is someone can help me .
236 [main] INFO org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#37eaab: startup date [Sat May 03 21:15:12 CEST 2014]; root of context hierarchy
472 [main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - L oading XML bean definitions from URL [file:/C:/Users/housseminfo/workspace/ERP_PCD/target/classes/META- INF/applicationContext.xml]
1017 [main] INFO org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
1242 [main] INFO org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
1272 [main] INFO org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#59727ed4: defining beans [datasource,persistenceUnitManager,entityManagerFactory,entityManager,transactionManager,o g.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annot ation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.Tr ansactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,op manager,metier,org.springframework.context.annotation.internalConfigurationAnnotationProces sor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springf ramework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context .annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.intern alPersistenceAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassP ostProcessor.importAwareProcessor]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/io/support/SpringFactoriesLoader
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(A bstractAutowireCapableBeanFactory.java:532)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abs tractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFacto ry.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(Default SingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.j ava:198)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(A bstractApplicationContext.java:741) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationC ontext.java:464)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init> (ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init> (ClassPathXmlApplicationContext.java:83)
at com.ensi.dao.Maintest.main(Maintest.java:13)
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/io/support/SpringFactoriesLoader
at org.springframework.beans.CachedIntrospectionResults.<clinit> (CachedIntrospectionResults.java:65)
at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.jav a:321)
at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptors(BeanWrapperImpl.java:328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterProperty DescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterProperty at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(A bstractAutowireCapableBeanFactory.java:1117)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(A bstractAutowireCapableBeanFactory.java:522)
.. 10 more
Caused by: java.lang.ClassNotFoundException: org.springframework.core.io.support.SpringFactoriesLoader
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 17 more
Hi its very clear from your exception that , you dont have all spring jars in your classpath.
if you are using maven add all dependencies in pom.xml.
otherwise download the jars from spring source and add them into project classpath.
once you add and run , it will work properly.
i don't see any aplication related errors over there. its only jar problem.
either missing jars or version mismatch. check it properly.
So I've figured out my error, now I'm just looking for some insight as to what is going on exactly. I am using Apache Tomcat Version 7.0.32. I am using this tutorial to set up pooling for JDBC. In my META-INF folder I made a context.xml file and put this in there.
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource type="javax.sql.DataSource" name="jdbc/gmustudent"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/official"
username="root" password="root"
maxActive="100" maxIdle="20" minIdle="15" initialSize="15" maxWait="10000" />
</Context>
I got this error when I wrote this
WARNING: Unexpected exception resolving reference
java.sql.SQLException: com.mysql.jdbc.Driver
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:699)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:631)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:485)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
at org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(DataSourceFactory.java:539)
at org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(DataSourceFactory.java:237)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at org.apache.catalina.core.NamingContextListener.addResource(NamingContextListener.java:1061)
at org.apache.catalina.core.NamingContextListener.createNamingContext(NamingContextListener.java:671)
at org.apache.catalina.core.NamingContextListener.lifecycleEvent(NamingContextListener.java:270)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5173)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:246)
... 29 more
Oct 31, 2012 11:23:25 AM org.apache.catalina.core.NamingContextListener addResource
WARNING: Failed to register in JMX: javax.naming.NamingException: com.mysql.jdbc.Driver
Oct 31, 2012 11:23:25 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8086"]
Oct 31, 2012 11:23:25 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Oct 31, 2012 11:23:25 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 794 ms
This error only comes up when I have this statement in my context.xml file. When I remove it no error.
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
The reason I want to make sure that I have it is because in the apache tomcat tutorial it says
factory is required, and the value should be org.apache.tomcat.jdbc.pool.DataSourceFactory
So then I did a little bit of research on SO and found a post saying that you need to add this jar to your lib folder if you have an older version of tomcat. So I added the jar and now it works but I would like to have some information as to what on earth is going on because I am using the newest tomcat version. So why when I specify a factory do I get an error. And what is this jar that I'm adding in and why is there very little documentation about it? Any information about what is going on here would be greatly appreciated.
The JDBC driver has to be visible to the same classloader as the data source factory itself. The data source factory library is placed in Tomcat's own /lib folder and thus loaded by Tomcat's "common" classloader.
Your problem sounds much like that you dropped the JDBC driver in webapp's /WEB-INF/lib. The webapp's /WEB-INF/lib is invisible to the "common" classloader. So technically, you have to place the JDBC driver in Tomcat's own /lib folder (or, at least, in a configurable path as specified by common.loader setting in /conf/catalina.properties) in order to make it visible to the data source factory.
Or, as you attempted, copying the data source factory into /WEB-INF/lib will also fix it. The webapp's /WEB-INF/lib has namely higher precedence in classloading than Tomcat's /lib folder. So if the data source factory is found in /WEB-INF/lib, it will be loaded from there. As the JDBC driver is also there, it will be seen. This is however not the right solution to your concrete problem, this is more a workaround, so you shouldn't do this.
There isn't exactly documentation which is specifically targeted to this issue. The Tomcat Class Loader HOW-TO will however help in understanding the class loading hierarchy in Tomcat.
See also:
The infamous java.sql.SQLException: No suitable driver found
How should I connect to JDBC database / datasource in a servlet based application?
Is it safe to use a static java.sql.Connection instance in a multithreaded system?
I had the same problem, your solution didn't work for me.
I had to add the 'mysql-connector-java-5.1.30-bin.jar' file to my lib folder for it to work, since i was using that driver :)
Cheers.