读书人

tomcat context札记

发布时间: 2012-09-03 09:48:39 作者: rapoo

tomcat context笔记

今天终于搞定Tomcat的Context了,conf/Context.xml是Tomcat公用的环境配置;若在Server.xml中增加<Context path="/test" docBase="D:\test" debug="0" reloadable="false"/>的话,则myApp/META-INF/Context.xml就没用了(被server.xml中的Context替代),Jndi 数据源或其他资源可直接定在里面,如:??
??? <Context path="/frame" docBase="C:\Java\jboss-4.0.1sp1\server\default\deploy\webroot.war" debug="0" reloadable="false">
????? <Resource name="UserTransaction" auth="Container"
??????????????????????????????????????????? type="javax.transaction.UserTransaction"
??????????????????????????????????????????? factory="org.objectweb.jotm.UserTransactionFactory"
??????????????????????????????????????????? jotm.timeout="60" />??????
????? <Resource name="sharkdb" type="javax.sql.DataSource"??????????????????????????????????????
????????????????????????????????????? password="helloworld" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
????????????????????????????????????? maxIdle="2" maxWait="5000" username="sa"
????????????????????????????????????? url="jdbc:microsoft:sqlserver://192.168.0.193:1433;DatabaseName=test_cyber3;SelectMethod=cursor" maxActive="4"/>
??????????????????????????????????????
???? <Resource name="cyberwaydb" type="javax.sql.DataSource"??????????????????????????????????????
????????????????????????????????????? password="helloworld" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
????????????????????????????????????? maxIdle="2" maxWait="5000" username="sa"
????????????????????????????????????? url="jdbc:microsoft:sqlserver://192.168.0.193:1433;DatabaseName=test_cyber3" maxActive="4"/>
???????
????? </Context>;
若在<GlobalNamingResources>中增加的JNDI或其他的,在App中需引用,才能使用,以下两种引用方式:
? A:在WEB-INF/web.xml 中配置如下:
<resource-ref>
????? <description>DB Connection</description>
????? <res-ref-name>jdbc/TestDB</res-ref-name>
????? <res-type>javax.sql.DataSource</res-type>
????? <res-auth>Container</res-auth>
? </resource-ref>
B:在yoursApp\META-INF\context.xml, 如下:
<?xml version='1.0' encoding='utf-8'?>
<Context path="/yoursApp" docBase="yoursApp"?
debug="5"???
reloadable="true"?
crossContext="true">
<ResourceLink name="mysqlDBConPool" global="mysqlDBConPool" type="javax.sql.DataSource"/>

</Context>

读书人网 >软件架构设计

热点推荐