Property binding of spring boot Tomcat JDBC pool
Let's take a look at the attribute binding code of spring boot Tomcat JDBC pool. The specific code is as follows:
Using the above configuration, it is finally found that the initial size, Max active, Max idle, min idle and other configurations are invalid, and the generated Tomcat JDBC datasource still uses the default configuration
Correct configuration
Note that the configuration properties of the specific Tomcat database connection pool are placed in spring datasource. Under the Tomcat attribute, so that it can take effect.
Source code analysis
DataSourceConfiguration. Tomcat
You can see that the datasourceproperties here are only spring The datasource directly controls the configuration of attributes, such as URL, username, password, and driverclassname. There are no specific attributes of Tomcat.
createDataSource
Org. Directly from createdatasource apache. tomcat. jdbc. pool. Poolproperties of datasource is also the default configuration
ConfigurationProperties
The specific magic lies in the code @ configurationproperties (prefix = "spring. Datasource. Tomcat"), which will return spring. Before the spring container constructs the proxy bean datasource. The attribute specified by Tomcat is set to org apache. tomcat. jdbc. pool. DataSource
Note that the annotation here is @ configurationproperties (prefix = "spring. Datasource. Tomcat"), and its prefix is spring datasource. The targetname of Tomcat propertiesconfigurationfactory is spring datasource. tomcat
Delegate to dobindpropertiestotarget method
Here, with the help of relaxeddatabinder Bind method
A relaxednames is created here, which can identify variants of multiple variables
RelaxedNames
That is, support org springframework. boot. bind. RelaxedNames@6ef81f31 [name = spring.datasource.tomcat, values = [spring.datasource.tomcat, spring_datasource_tomcat, springdatasourcetomcat, springdatasourcetomcat, spring.datasource.tomcat, spring_datasource_tomcat, springdatasourcetomcat]] the writing method configured in these 7