tomcat 6 数据库连接池配置
??????? 前几天,在客户现场,DWR报了“无法获得连接”的错误,回来后在tomcat上配了数据库连接池。记录一下配置的步骤,备用!
??????? 一 在apache-tomcat-6.0.14\conf\context.xml中Context标签内增内以下内容:
??????
???????中Context标签内增内以下内容:
??????
????????
????????????? <Resource name="jdbc/aaa"
?????????????????????? ?auth="Container"
????????????????????????type="javax.sql.DataSource"
?????????????????????? password="123"?
???????????????????????username="sa"
?????????????????????? driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
?????????????????????? url="jdbc:sqlserver://192.168.0.26:1433;databaseName=dbs"
?????????????????????? maxActive="130"?
????????????????????? ?maxIdle="30"???
?????????????????????? maxWait="5000"
?????????????????????? testOnBorrow="true"
?????????????????????? testOnReturn="true"
?????????????????????? testWhileIdle="true"
?????????????????????? validationQuery="select 1"
?????????????????????? removeAbandoned="true"??
????????????? ??????? ?removeAbandonedTimeout="60"??
????????????? ????? ? logAbandoned="true"
??? />?
??? 二 在应用的web.xml中加入以下内容:
???????
????????? <resource-ref>
????????????????? <description>datasource</description>
????? ????????? ?<res-ref-name>jdbc/aaa</res-ref-name> //要和 <Resource name="jdbc/aaa" 对应
???????????????? ?<res-type>javax.sql.DataSource</res-type>
???????????????? ?<res-auth>Container</res-auth>
????????? ?</resource-ref>
???????? 三? 更改spring配置文件,改为:
?????????
????????? <bean id="dataSource" style="margin: 0cm 0cm 0pt;">??? ????????????? <property name="jndiName" value="java:comp/env/jdbc/wgpx"></property>???
??????????????? </bean>
?
???????
?
???????? tomcat连接池一些属性的作用:
???????????????? maxActive 连接池支持的最大连接数
???????????????? maxIdle 连接池中最多可空闲maxIdle个连接
???????????????? minIdle 连接池中最少空闲maxIdle个连接
???????????????? initialSize 初始化连接数目
???????????????? maxWait 连接池中连接用完时,新的请求等待时间,毫秒
???????????????