Tomcat下连接池的配置(续)

  唉,郁闷,昨天配好的TOMCAT+ MYSQL连接池,今天搞了一上午,用的好好的,还把原来的程序从XML文件存储数据转化为了数据库存储的,但是噩梦马上就来了,一个不小心,在Eclipse里把几个servlet和一 些东西重名个名,所以就在MyEclipse里重新部署一下,就从这开始,问题就来了,启动TOMCAT就是:

严重: Null component Catalina:type=DataSource,path=/webtest,host=localhost,class=javax.sql.DataSource,name="jdbc/webtest"
2007-01-07 22:43:59,890[org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/webtest]]-[位置:org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3653)]-[DEBUG]Sending application start events
2007-01-07 22:43:59,890[org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/webtest]]-[位置:org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3528)]-[DEBUG]Starting filters
2007-01-07 22:43:59,890[org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/webtest]]-[位置:org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3537)]-[DEBUG] Starting filter 'loginFilter'
2007-01-07 22:43:59,906[org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/webtest]]-[位置:org.apache.catalina.core.ApplicationContext.log(ApplicationContext.java:636)]-[INFO]D:/Apache/Tomcat/webapps/webtest/WEB-INF/user.xml
javax.naming.NameNotFoundException: Name java:comp is not bound in this Context
 at org.apache.naming.NamingContext.lookup(NamingContext.java:769)
 at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
 at javax.naming.InitialContext.lookup(InitialContext.java:351)
 at cn.edu.ctgu.bean.DBConnectionManager.<clinit>(DBConnectionManager.java:24)
 at cn.edu.ctgu.bean.UserManagerDBImpl.<init>(UserManagerDBImpl.java:41)
 at cn.edu.ctgu.bean.UserManagerDBImpl.getInstance(UserManagerDBImpl.java:29)
 at cn.edu.ctgu.bean.ManagerFactory.creteDBUserManager(ManagerFactory.java:26)
 at cn.edu.ctgu.servlets.SaveUserServlet.init(SaveUserServlet.java:134)

之类的异常,让我糊涂了,昨天可以的,今天什么都没改啊,怎么就出问题了呢

后来仔细想了想,是不是MyEclipse给我搞了什么好东西了,算了,自己手工部署一下

怪了,一切正常,怎么手工部署就没问题呢? 

再来一次,MyEclipse部署

哈哈,有来问题了,还是那个javax.naming.NameNotFoundException: Name java:comp is not bound in this Context,开来是这的问题了,把两次的部署比较了一下,发现了点不同的东西

手工部署的时候D:/Apache/Tomcat/webapps/webtest/WEB-INF/lib

比myEclipse里少两个jar包:naming-factory-dbcp.jar和naming-factory.jar

把这两个删除,呵呵,居然正常了,怪哦!

仔细想了想,大概是类加载顺序,什么的问题,糊涂了,找点资料

Apache Tomcat 5.5 Servlet/JSP 容器

Class Loader HOW-TO

Printer Friendly Version
print-friendly
version
Quick Start

程序开发员和部署员要决定在哪里放置类和资源文件以便它们可以被网络程序使用, 95%的这些决定由下面的这些条例覆盖:

  • 对于某个网络程序所特有的类和资源,把这些未包装的类和资源放置在你的网络程序档案/WEB-INF/classes目录下面,或者把包含这些类和资源的JAR文件放置在你的网络程序档案/WEB-INF/lib目录下面。
  • 对于必须被所有网络程序所共享的类和资源,把未包装的这些类和资源放置在$CATALINA_BASE/shared/classes下面,或者把包含这些类和资源的JAR文件放置在$CATALINA_BASE/shared/lib下面。
Overview

象许多服务器程序一样,Tomcat 5安装各种不同类型的类loaders(那就是,实现java.lang.ClassLoader的类)来允许容器的不同部分,以及运行在容器上的网络程序,可以访问不同贮存部分的类和资源。这个机制是用来提供Servlet Specification, 2.4版——特别是9.4 和 9.6章节里定义的功能。

In a J2SE 2 (that is, J2SE 1.2 or later) environment, class loaders are arranged in a parent-child tree. Normally, when a class loader is asked to load a particular class or resource, it delegates the request to a parent class loader first, and then looks in its own repositories only if the parent class loader(s) cannot find the requested class or resource. The model for web application class loaders differs slightly from this, as discussed below, but the main principles are the same.

当Tomcat 5启动后,它产生一组类装载器,这些类装载器被组织成如下的父子关系,父类装载器在子类装载器之上:

Bootstrap 
| 
System 
| 
Common 
/ / 
Catalina Shared 
/ / 
Webapp1 Webapp2 ...

每一个类装载器的特征,包括可被使用的类和资源的来源,在下面的章节有详细讨论。

Class Loader Definitions

如上面的图表显示,Tomcat 5在它启动时产生如下的类装载器:

  • Bootstrap - 这个类装载器包含Java虚拟器提供的基本的运行时间类,加上在System Extensions 目录( $JAVA_HOME/jre/lib/ext )里的JAR文件中所有的类。注意——有些Java虚拟器(JVMs)也许把它作为不止一个类装载器用,或者作为一个类装载器用。
  • System - 这个类装载器通常是以CLASSPATH环境变量的内容为基础来初始化的。所有的这些类既可被Tomcat内部classes使用,又可被网络程序使用。不过,标准的Tomcat 5启动脚本( $CATALINA_HOME/bin/catalina.sh or %CATALINA_HOME%/bin/catalina.bat )完全忽略了CLASSPATH环境变量自身的内容,相反从下面的贮藏室去建造系统类装载器:
    • $CATALINA_HOME/bin/bootstrap.jar - 包含用来初始化Tomcat 5服务器的main()方法,以及它所依赖的类装载器执行类。
    • $JAVA_HOME/lib/tools.jar - 包含用来把JSP页面转换成servlet类的"javac"编译器。
    • $CATALINA_HOME/bin/commons-logging-api.jar - Jakarta commons 记录应用程序界面。
    • $CATALINA_HOME/bin/commons-daemon.jar - Jakarta commons daemon API.
    • jmx.jar - JMX 1.2 执行。
  • Common - This class loader contains additional classes that are made visible to both Tomcat internal classes and to all web applications. Normally, application classes should NOT be placed here. All unpacked classes and resources in $CATALINA_HOME/common/classes, as well as classes and resources in JAR files under the $CATALINA_HOME/commons/endorsed, $CATALINA_HOME/commons/i18n and $CATALINA_HOME/common/lib directories, are made visible through this class loader. By default, that includes the following:
    • commons-el.jar - Jakarta commons el, 执行Jasper使用的表达语言。
    • jasper-compiler.jar - The JSP 2.0 编译器。
    • jasper-compiler-jdt.jar - The Eclipse JDT Java compiler.
    • jasper-runtime.jar - The JSP 2.0 运行时间。
    • jsp-api.jar - The JSP 2.0 应用编程界面(API)。
    • naming-common.jar - 被Tomcat 5用来代表in-memory命名contexts的JNDI实现。
    • naming-factory.jar - 被Tomcat 5用来决定企业资源索引(EJB, connection pools)的JNDI实现。
    • naming-factory-dbcp.jar - Jakarta commons DBCP, providing a JDBC connection pool to web applications. The classes have been moved out of their default org.apache.commons package.
    • naming-java.jar - Handler for the java: namespace.
    • naming-resources.jar - The specialized JNDI naming context implementation used to represent the static resources of a web application. This is not related to the support of the J2EE ENC, and cannot be removed.
    • servlet-api.jar - The Servlet 2.4 API.
    • tomcat-i18n-**.jar - Optional JARs containing resource bundles for other languages. As default bundles are also included in each individual JAR, they can be safely removed if no internationalization of messages is needed.
  • Catalina - 这个类装载器被初始化后包含执行Tomcat 5自身必须的所有类和资源。这些类和资源完全可被网络程序使用。所有的在$CATALINA_HOME/server/classes里未包装的类和资源,以及$CATALINA_HOME/server/lib下JAR文件里的类和资源,通过这个类装载器可被使用。在默认的情况下,有下面的这些:
    • catalina.jar - Tomcat 5的执行Catalina servlet容器部分。
    • catalina-ant.jar - Some Ant tasks which can be used to manage Tomcat using the manager web application.
    • catalina-optional.jar - Some optional components of Catalina.
    • commons-modeler.jar - A model MBeans implementation used by Tomcat to expose its internal objects through JMX.
    • servlets-xxxxx.jar - 与每个内部servlet相关联的类,这些内部servlet提供一部分Tomcat的功能。它们是分离开的,这样一来,如果相应的服务不需要的话,它们就可以完全被删除,或者它们需要特别的安全管理员许可。
    • tomcat-coyote.jar - Coyote API.
    • tomcat-http11.jar - 独立的Java HTTP/1.1 连接器。
    • tomcat-ajp.jar - Classes for the Java portion of the AJP web server connector, which allows Tomcat to run behind web servers such as Apache and iPlanet iAS and iWS.
    • tomcat-util.jar - 一些Tomcat必需的Utility类。
  • Shared - 这个类装载器是放置被所有网络程序共享的类和资源的地方(除非Tomcat内部classes也需要访问它们,要是这样,你就得把它们放在Common这个类装载器)。所有的在$CATALINA_BASE/shared/classes 里未包装的类和资源,以及$CATALINA_BASE/shared/lib 下JAR文件里的类和资源,通过这个类装载器可被使用。如果多个Tomcat实例使用同样的$CATALINA_BASE环境变量运行,那么这个类装载器的储藏室就和$CATALINA_BASE有关,而不是和$CATALINA_HOME有关。
  • WebappX - 为在单个Tomcat 5实例中被部署的每一个网络程序所产生的类装载器。在你的网络程序档案/WEB-INF/classes目录里所有的未包装的类和资源,以及网络程序档案/WEB-INF/lib目录下JAR文件里的类和资源,可被这个Webapp里的程序使用,而不能其他程序使用。

As mentioned above, the web application class loader diverges from the default Java 2 delegation model (in accordance with the recommendations in the Servlet Specification, version 2.3, section 9.7.2 Web Application Classloader). When a request to load a class from the web application's WebappX class loader is processed, this class loader will look in the local repositories first, instead of delegating before looking. There are exceptions. Classes which are part of the JRE base classes cannot be overriden. For some classes (such as the XML parser components in J2SE 1.4+), the J2SE 1.4 endorsed feature can be used (see the common classloader definition above). Last, any JAR containing servlet API classes will be ignored by the classloader. All other class loaders in Tomcat 5 follow the usual delegation pattern.

因此,从一个网络程序的角度来看,类和资源的装载以这样的顺序在下列贮藏室进行查找:

  • 你的JVM的Bootstrap类
  • 系统类装载器类(描述如上)
  • 你的网络程序的/WEB-INF/classes
  • 你的网络程序的/WEB-INF/lib/*.jar
  • $CATALINA_HOME/common/classes
  • $CATALINA_HOME/common/endorsed/*.jar
  • $CATALINA_HOME/common/i18n/*.jar
  • $CATALINA_HOME/common/lib/*.jar
  • $CATALINA_BASE/shared/classes
  • $CATALINA_BASE/shared/lib/*.jar
XML Parsers and J2SE 1.4

Among many other changes, the J2SE 1.4 release packages the JAXP APIs, and a version of Xerces, inside the JRE. This has impacts on applications that wish to use their own XML parser.

In previous versions of Tomcat 5, you could simply replace the XML parser in the $CATALINA_HOME/common/lib directory to change the parser used by all web applications. However, this technique will not be effective when you are running on J2SE 1.4, because the usual class loader delegation process will always choose the implementation inside the JDK in preference to this one.

JDK 1.4支持被称为"Endorsed Standards Override Mechanism" 的机制,来允许替代在JCP以外产生的APIs(例如DOM 和W3C里的SAX)。也可以使用它来更新XML语法分析式执行。更多信息,请参看 http://java.sun.com/j2se/1.4/docs/guide/standards/index.html

Tomcat通过在启动容器的命令行里加入系统属性设置-Djava.endorsed.dirs=$CATALINA_HOME/common/endorsed 来利用这个机制。因此,你可以取代安装在这个目录里的语法分析式,它甚至可以在JDK 1.4系统上使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值