Configuration and use of druid data sources
I haven't updated the technical blog for a long time, and this blog will be re-launched for the technical record after practice.
Next, let's introduce how to configure an druid data source.
First of all, to introduce the dependency of druid in pom.xml, you should add version. I uniformly define version in parent, and I recommend using a stable version in the central repository.
Com.alibaba druid
Then, the general data source is configured in the context of spring, and the configuration file format is as follows:
Load property configuration file
Next, configure the property file. The druid data source supports password protection. Generate password protection using the following command
Java-cp druid-1.0.16.jar com.alibaba.druid.filter.config.ConfigTools you_password
Jdbc.driver=com.mysql.jdbc.Driverjdbc.jdbcUrl=jdbc:mysql://10.10.5.204:3306/v3?useUnicode=true&characterEncoding=utf-8jdbc.username=rootjdbc.publickey=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOMUL6IbPTQkUcWoZSVROIEcgTAArcLP2rtNFaahm38PYqWVE92apcMqt0YxzTVSilGgUwIul9f5ZhvzpWGap4sCAwEAAQ==jdbc.password=kBJz+ij4HbnU4caQ6iJIBJtEDBHKXZoUsSSbhOSHzY0tRrMNOWcPZV/EIrlvAn+4lHQv7FfvhL6Z0CiUNY0ZmQ==jdbc.maxActive=8
Finally, to configure the monitoring page, configure the monitoring page in web.xml
DruidStatView com.alibaba.druid.support.http.StatViewServlet resetEnable false loginUsername genilex loginPassword 123456 DruidStatView / druid/*
The above druid data sources are configured.
The following tests can be done to verify the success of the configuration.
There are also some frequently asked questions, please refer to the official wiki
Https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98