Tomacat中使用JNDI
一、JavaBean
0. IntroductionThis resource factory can be used to create objects of any Java class that conforms to standard JavaBeans naming conventions (i.e. it has a zero-arguments constructor, and has property setters that conform to the setFoo() naming pattern. The resource factory will create a new instance of the appropriate bean class every time a The steps required to use this facility are described below. 1. Create Your JavaBean ClassCreate the JavaBean class which will be instantiated each time that the resource factory is looked up. For this example, assume you create a class
2. Declare Your Resource RequirementsNext, modify your web application deployment descriptor (
WARNING - Be sure you respect the element ordering that is required by the DTD for web application deployment descriptors! See the Servlet Specification for details. 3. Code Your Application's Use Of This ResourceA typical use of this resource environment reference might look like this:
4. Configure Tomcat's Resource FactoryTo configure Tomcat's resource factory, add an element like this to the
Note that the resource name (here, |
二、数据源:
0. IntroductionMany web applications need to access a database via a JDBC driver, to support the functionality required by that application. The J2EE Platform Specification requires J2EE Application Servers to make available a DataSource implementation (that is, a connection pool for JDBC connections) for this purpose. Tomcat 6 offers exactly the same support, so that database-based applications you develop on Tomcat using this service will run unchanged on any J2EE server. For information about JDBC, you should consult the following:
NOTE - The default data source support in Tomcat is based on the DBCP connection pool from the Commons project. However, it is possible to use any other connection pool that implements 1. Install Your JDBC DriverUse of the JDBC Data Sources JNDI Resource Factory requires that you make an appropriate JDBC driver available to both Tomcat internal classes and to your web application. This is most easily accomplished by installing the driver's JAR file(s) into the 2. Declare Your Resource RequirementsNext, modify the web application deployment descriptor (
WARNING - Be sure you respect the element ordering that is required by the DTD for web application deployment descriptors! See the Servlet Specification for details. 3. Code Your Application's Use Of This ResourceA typical use of this resource reference might look like this:
Note that the application uses the same resource reference name that was declared in the web application deployment descriptor. This is matched up against the resource factory that is configured in the 4. Configure Tomcat's Resource FactoryTo configure Tomcat's resource factory, add an element like this to the
Note that the resource name (here, This example assumes that you are using the HypersonicSQL database JDBC driver. Customize the The configuration properties for Tomcat's standard data source resource factory (
|
以上内容出自tomcat文档