關於tomcat啓動時的警告 :Property maxActive is not used in DBCP2, use maxTotal instead. 和 Property maxWait i

我們現在用的tomcat大概都是8.5 或是9.0,這些版本的tomcat內置的DBCP2,和以前老版本如tomcat 7的連接池不一樣,7.0等老版本用的是DBCP。

tomcat 7等老版本中,內置連接池時 context.xml文件 的默認配置示例:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
  <Resource name="jdbc/day28" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWaitMillis="10000"
               username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/day28"/>
</Context>

在老版本的tomcat裏面關於允許的最大連接數用maxActive來表示,最大等待延用maxWait來表示

我們現在用的是新版本的tomcat,新版本內置的連接池已經升級了,所以如果我們繼續使用這個配置就會出現如下圖所示警告:

警告原文如下:

七月 05, 2018 1:55:06 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory [D:\learn\JavaWeb\apache-tomcat\apache-tomcat-9.0.7\webapps\day28_struts2_final]
七月 05, 2018 1:55:06 下午 org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
警告: Name = day28 Property maxActive is not used in DBCP2, use maxTotal instead. maxTotal default value is 8. You have set value of "100" for "maxActive" property, which is being ignored.
七月 05, 2018 1:55:06 下午 org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
警告: Name = day28 Property maxWait is not used in DBCP2 , use maxWaitMillis instead. maxWaitMillis default value is -1. You have set value of "10000" for "maxWait" property, which is being ignored.
七月 05, 2018 1:55:06 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
七月 05, 2018 1:55:07 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [D:\learn\JavaWeb\apache-tomcat\apache-tomcat-9.0.7\webapps\day28_struts2_final] has finished in [1,469] ms

這個警告其實已經把話說的很明白了,既然8.5,9.0tomcat內置的是DBCP2,已經使用 maxTotal來取代maxActive、使用 maxWaitMillis來取代maxWait,

因此我們只需要將自己的配置文件中的maxActive替換成maxTotalmaxWait替換成maxWaitMillis即可。

<?xml version="1.0" encoding="UTF-8"?>
<Context>
  <Resource name="jdbc/day28" auth="Container" type="javax.sql.DataSource"
               maxTotal="100" maxIdle="30" maxWaitMillis="10000"
               username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/day28"/>
</Context>

警告消失了:

七月 05, 2018 3:26:15 下午 org.apache.catalina.startup.HostConfig undeploy
信息: Undeploying context [/day28_struts2_final]
七月 05, 2018 3:26:15 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory [D:\learn\JavaWeb\apache-tomcat\apache-tomcat-9.0.7\webapps\day28_struts2_final]
七月 05, 2018 3:26:16 下午 org.apache.jasper.servlet.TldScanner scanJars
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
七月 05, 2018 3:26:16 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [D:\learn\JavaWeb\apache-tomcat\apache-tomcat-9.0.7\webapps\day28_struts2_final] has finished in [1,087] ms

附上:DBCP2中配置參數詳解鏈接:http://bsr1983.iteye.com/blog/2092467

本文參考鏈接如下:https://blog.csdn.net/vr_jia/article/details/74530389

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章