web-dev-qa-db-ja.com

Tomcat8にアップグレードした場合のClassNotFoundException

最近、NetBeans IDEをv7.3からv8にアップグレードしましたが、DBへの接続中に、サーバーの起動時にアプリケーションが突然例外をスローしました。 IDEのこれら2つのバージョンの唯一の違いは、後者がTomcat8を使用していることです。

例外ログ:

javax.naming.NamingException: Could not load resource factory class [Root exception is Java.lang.ClassNotFoundException: org.Apache.Tomcat.dbcp.dbcp.BasicDataSourceFactory]
    at org.Apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.Java:82)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.Java:321)
    at org.Apache.naming.NamingContext.lookup(NamingContext.Java:841)
    at org.Apache.naming.NamingContext.lookup(NamingContext.Java:152)
    at org.Apache.naming.NamingContext.lookup(NamingContext.Java:829)
    at org.Apache.naming.NamingContext.lookup(NamingContext.Java:152)
    at org.Apache.naming.NamingContext.lookup(NamingContext.Java:829)
    at org.Apache.naming.NamingContext.lookup(NamingContext.Java:152)
    at org.Apache.naming.NamingContext.lookup(NamingContext.Java:829)
    at org.Apache.naming.NamingContext.lookup(NamingContext.Java:166)
    at org.Apache.naming.SelectorContext.lookup(SelectorContext.Java:157)
    at javax.naming.InitialContext.lookup(InitialContext.Java:411)
    at com.istore.core.listeners.AppContextListener.initdb(AppContextListener.Java:44)
    at com.istore.core.listeners.AppContextListener.contextInitialized(AppContextListener.Java:27)
    at org.Apache.catalina.core.StandardContext.listenerStart(StandardContext.Java:4738)
    at org.Apache.catalina.core.StandardContext.startInternal(StandardContext.Java:5158)
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:150)
    at org.Apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.Java:726)
    at org.Apache.catalina.core.ContainerBase.addChild(ContainerBase.Java:702)
    at org.Apache.catalina.core.StandardHost.addChild(StandardHost.Java:697)
    at org.Apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.Java:579)
    at org.Apache.catalina.startup.HostConfig.deployApps(HostConfig.Java:455)
    at org.Apache.catalina.startup.HostConfig.check(HostConfig.Java:1554)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:606)
    at org.Apache.Tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.Java:300)
    at com.Sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.Java:819)
    at com.Sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.Java:801)
    at org.Apache.catalina.manager.ManagerServlet.check(ManagerServlet.Java:1428)
    at org.Apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.Java:885)
    at org.Apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.Java:343)
    at javax.servlet.http.HttpServlet.service(HttpServlet.Java:618)
    at javax.servlet.http.HttpServlet.service(HttpServlet.Java:725)
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:301)
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:206)
    at org.Apache.Tomcat.websocket.server.WsFilter.doFilter(WsFilter.Java:52)
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:239)
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:206)
    at org.Apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.Java:108)
    at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:239)
    at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:206)
    at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:219)
    at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:106)
    at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:615)
    at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:136)
    at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:74)
    at org.Apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.Java:610)
    at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:88)
    at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:516)
    at org.Apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.Java:1015)
    at org.Apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.Java:652)
    at org.Apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.Java:222)
    at org.Apache.Tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.Java:1575)
    at org.Apache.Tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.Java:1533)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1145)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:615)
    at Java.lang.Thread.run(Thread.Java:724)
Caused by: Java.lang.ClassNotFoundException: org.Apache.Tomcat.dbcp.dbcp.BasicDataSourceFactory
    at org.Apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.Java:1284)
    at org.Apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.Java:1132)
    at org.Apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.Java:80)
    ... 58 more

META-INF/context.xml

<!-- PostgreSQL Datasource -->
<Resource auth="Container" driverClassName="org.postgresql.Driver" factory="org.Apache.Tomcat.dbcp.dbcp.BasicDataSourceFactory" maxActive="50" maxIdle="10" maxWait="-1" name="jdbc/mydb" type="javax.sql.DataSource" url="jdbc:postgresql://myorg.corp.net:5432/mydb" username="abc" password="def" />

ご案内ください。

8
Nital

デフォルトのファクトリの名前がTomcat7とTomcat8の間で変更されました。いくつかの属性名も変更されました。これはすべて、Tomcat8でDBCP1.xからDBCP2.xに切り替えた結果です。META-INF/ context.xmlファイルに次のものが必要です。

<!-- PostgreSQL Datasource -->
<Resource auth="Container"
          driverClassName="org.postgresql.Driver"
          factory="org.Apache.Tomcat.dbcp.dbcp2.BasicDataSourceFactory"
          maxTotal="50"
          maxIdle="10"
          maxWaitMillis="-1"
          name="jdbc/mydb"
          type="javax.sql.DataSource"
          url="jdbc:postgresql://myorg.corp.net:5432/mydb"
          username="abc"
          password="def" />

このファクトリはデフォルトでタイプjavax.sql.DataSourceのリソースに使用されるため、その属性をすべてまとめて削除できます。その他の変更は次のとおりです。

maxActive -> maxTotal
maxWait   -> maxWaitMillis
18
Mark Thomas

Tomcat-dbcp-8.0.0-RC1.jarlibフォルダーにTomcat8が必要です。 org.Apache.Tomcat.dbcp.dbcp2.BasicDataSourceFactorycommons-dbcp.jarのパッケージ構造は、他のTomcatバージョンとは異なります。

2
Imran Bhat