Detailed description of Druid connection pool configuration in JSP Spring, springdruid
Druid connection pool configuration in JSP Spring
Jdbc. properties
url=jdbc:postgresql://***.***.***.***:****/****username=***password=***
Configure bean in applicationContext. xml
<! -- Alibaba druid database connection pool --> <bean id = "dataSource" class = "com. alibaba. druid. pool. druidDataSource "init-method =" init "destroy-method =" close "> <! -- Basic attribute url, user, password --> <property name = "url" value = "$ {url}"/> <property name = "username" value = "$ {username} "/> <property name =" password "value =" $ {password} "/> <! -- Configure the initialization size, minimum, and maximum --> <property name = "initialSize" value = "1"/> <property name = "minIdle" value = "1"/> <property name = "maxActive" value = "20"/> <! -- Configure the timeout time for obtaining connections --> <property name = "maxWait" value = "60000"/> <! -- Configure the interval for a test to detect idle connections that need to be closed, in milliseconds --> <property name = "timeBetweenEvictionRunsMillis" value = "60000"/> <! -- Configure the minimum time for a connection to survive in the pool, unit: millisecond --> <property name = "minEvictableIdleTimeMillis" value = "300000"/> <property name = "validationQuery" value = "SELECT 'x'"/> <property name = "testWhileIdle" value = "true"/> <property name = "testOnBorrow" value = "false"/> <property name = "testOnReturn" value = "false"/> <! -- Enable PSCache, specify the PSCache size for each connection --> <property name = "poolPreparedStatements" value = "true"/> <property name = "maxPoolPreparedStatementPerConnectionSize" value = "20"/> <! -- Configure the filters intercepted by monitoring statistics, and the SQL statement on the monitoring page cannot be used for statistics after removal --> <property name = "filters" value = "stat"/> </bean>
Monitoring configuration web. xml
<filter> <filter-name>DruidWebStatFilter</filter-name> <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class> <init-param> <param-name>exclusions</param-name> <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value> </init-param> </filter> <filter-mapping> <filter-name>DruidWebStatFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>DruidStatView</servlet-name> <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>DruidStatView</servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping>
This configuration allows you to access the monitoring page. After configuration, you can use http: // ip: port/project name/druid/index.html
Monitor database access performance
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!