├── LICENSE ├── README.md ├── pom.xml └── src └── main ├── java └── cn │ └── binux │ └── druid │ ├── DruidAutoConfiguration.java │ ├── DruidMonitorAutoConfiguration.java │ ├── DruidMonitorProperties.java │ └── DruidProperties.java └── resources └── META-INF └── spring.factories /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | spring-boot-starter-druid 2 | 3 | 配置示例 4 | ``` 5 | #DRUID 6 | druid: 7 | url: jdbc:mysql://localhost:3306/springboottest 8 | driver-class: com.mysql.jdbc.Driver 9 | username: root 10 | password: OZo+t9QET+ctzd5Esn9q0GJP5hXtWWIKEsX8c4/w6z4C4AnxrwpvySNgBS89XdazOavjXXZp0oeZtQ3P9lLGEA== 11 | initial-size: 1 12 | min-idle: 1 13 | max-active: 20 14 | test-on-borrow: true 15 | max-wait: 60000 16 | time-between-eviction-runs-millis: 60000 17 | min-evictable-idle-time-millis: 300000 18 | validation-query: SELECT 1 FROM DUAL 19 | test-While-Idle: true 20 | test-on-return: false 21 | pool-prepared-statements: false 22 | max-pool-prepared-statement-per-connection-size: 20 23 | filters: stat,wall,log4j,config 24 | connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000;config.decrypt=true 25 | monitor: 26 | enabled: enabled # 配置此属性Monitor才生效 27 | druid-stat-view: /druid/* 28 | druid-web-stat-filter: /* 29 | allow: 219.230.50.107,127.0.0.1 30 | deny: 219.230.50.108 31 | login-username: admin 32 | login-password: 123456 33 | exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' 34 | reset-enable: false 35 | ``` 36 | 37 | 查看[Druid配置](https://github.com/alibaba/druid/wiki/DruidDataSource配置属性列表) 38 | 39 | `druid.monitor.enabled=enabled` 时Monitor才生效 40 | 41 | 配置就不讲了,不懂的自己`Google`去 -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | cn.binux 7 | spring-boot-starter-druid 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-starter-dubbox 12 | Spring Boot Starter Druid 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.2.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-configuration-processor 39 | true 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-test 44 | test 45 | 46 | 47 | 48 | com.alibaba 49 | druid 50 | 1.0.20 51 | 52 | 53 | 54 | 55 | 56 | 57 | releases 58 | Nexus Release Repository 59 | http://localhost:8077/nexus/content/repositories/releases/ 60 | 61 | 62 | snapshots 63 | Nexus Snapshot Repository 64 | http://localhost:8077/nexus/content/repositories/snapshots/ 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /src/main/java/cn/binux/druid/DruidAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package cn.binux.druid; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.autoconfigure.AutoConfigureBefore; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 9 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 10 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | import javax.sql.DataSource; 15 | import java.sql.SQLException; 16 | 17 | /** 18 | * Druid自动配置 19 | * 20 | * @author xubin. 21 | * @create 2017-04-05 22 | */ 23 | 24 | @Configuration 25 | @ConditionalOnClass(DruidDataSource.class) 26 | @EnableConfigurationProperties(DruidProperties.class) 27 | @AutoConfigureBefore(DataSourceAutoConfiguration.class) 28 | public class DruidAutoConfiguration { 29 | 30 | private static final Logger logger = LoggerFactory.getLogger(DruidAutoConfiguration.class); 31 | 32 | @Autowired 33 | private DruidProperties properties; 34 | 35 | @Bean 36 | public DataSource dataSource() { 37 | DruidDataSource dataSource = new DruidDataSource(); 38 | dataSource.setUrl(properties.getUrl()); 39 | dataSource.setUsername(properties.getUsername()); 40 | dataSource.setPassword(properties.getPassword()); 41 | if (properties.getInitialSize() > 0) { 42 | dataSource.setInitialSize(properties.getInitialSize()); 43 | logger.info("setInitialSize --->" + properties.getInitialSize()); 44 | } 45 | if (properties.getMinIdle() > 0) { 46 | dataSource.setMinIdle(properties.getMinIdle()); 47 | logger.info("setInitialSize --->" + properties.getInitialSize()); 48 | } 49 | if (properties.getMaxActive() > 0) { 50 | dataSource.setMaxActive(properties.getMaxActive()); 51 | logger.info("setMaxActive --->" + properties.getMaxActive()); 52 | } 53 | if (properties.getTestOnBorrow() != null) { 54 | dataSource.setTestOnBorrow(properties.getTestOnBorrow()); 55 | logger.info("setTestOnBorrow --->" + properties.getTestOnBorrow()); 56 | } 57 | if (properties.getMaxWait() > 0) { 58 | dataSource.setMaxWait(properties.getMaxWait()); 59 | logger.info("setMaxWait --->" + properties.getMaxWait()); 60 | } 61 | if (properties.getTimeBetweenEvictionRunsMillis() > 0) { 62 | dataSource.setTimeBetweenEvictionRunsMillis(properties.getTimeBetweenEvictionRunsMillis()); 63 | logger.info("setTimeBetweenEvictionRunsMillis --->" + properties.getTimeBetweenEvictionRunsMillis()); 64 | } 65 | if (properties.getMinEvictableIdleTimeMillis() > 0) { 66 | dataSource.setMinEvictableIdleTimeMillis(properties.getMinEvictableIdleTimeMillis()); 67 | logger.info("setMinEvictableIdleTimeMillis --->" + properties.getMinEvictableIdleTimeMillis()); 68 | } 69 | if (properties.getValidationQuery() != null) { 70 | dataSource.setValidationQuery(properties.getValidationQuery()); 71 | logger.info("setValidationQuery --->" + properties.getValidationQuery()); 72 | } 73 | if (properties.getTestWhileIdle() != null) { 74 | dataSource.setTestWhileIdle(properties.getTestWhileIdle()); 75 | logger.info("setTestWhileIdle --->" + properties.getTestWhileIdle()); 76 | } 77 | if (properties.getTestOnReturn() != null) { 78 | dataSource.setTestOnReturn(properties.getTestOnReturn()); 79 | logger.info("setTestOnReturn --->" + properties.getTestOnReturn()); 80 | } 81 | if (properties.getPoolPreparedStatements() != null) { 82 | dataSource.setPoolPreparedStatements(properties.getPoolPreparedStatements()); 83 | logger.info("setPoolPreparedStatements --->" + properties.getPoolPreparedStatements()); 84 | } 85 | if (properties.getMaxPoolPreparedStatementPerConnectionSize() > 0) { 86 | dataSource.setMaxPoolPreparedStatementPerConnectionSize(properties.getMaxPoolPreparedStatementPerConnectionSize()); 87 | logger.info("setMaxPoolPreparedStatementPerConnectionSize --->" + properties.getMaxPoolPreparedStatementPerConnectionSize()); 88 | } 89 | if (properties.getFilters() != null) { 90 | try { 91 | dataSource.setFilters(properties.getFilters()); 92 | logger.info("setFilters --->" + properties.getFilters()); 93 | } catch (SQLException e) { 94 | e.printStackTrace(); 95 | logger.error("setInitialSize error"); 96 | } 97 | } 98 | if (properties.getConnectionProperties() != null) { 99 | dataSource.setConnectionProperties(properties.getConnectionProperties()); 100 | logger.info("setConnectionProperties --->" + properties.getConnectionProperties()); 101 | } 102 | 103 | try { 104 | dataSource.init(); 105 | logger.info("dataSource.init()"); 106 | } catch (SQLException e) { 107 | throw new RuntimeException(e); 108 | } 109 | return dataSource; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/cn/binux/druid/DruidMonitorAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | package cn.binux.druid; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import com.alibaba.druid.support.http.StatViewServlet; 5 | import com.alibaba.druid.support.http.WebStatFilter; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 11 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 12 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 13 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 14 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 15 | import org.springframework.context.annotation.Bean; 16 | import org.springframework.context.annotation.Configuration; 17 | 18 | import javax.sql.DataSource; 19 | 20 | /** 21 | * Druid自动配置 22 | * 23 | * @author xubin. 24 | * @create 2017-04-05 25 | */ 26 | 27 | @Configuration 28 | @ConditionalOnClass(DruidDataSource.class) 29 | @EnableConfigurationProperties(DruidMonitorProperties.class) 30 | @ConditionalOnProperty(prefix = "druid.monitor",havingValue = "enabled",value = "enabled",matchIfMissing = false) 31 | @AutoConfigureAfter(DataSource.class) 32 | public class DruidMonitorAutoConfiguration { 33 | 34 | private static final Logger logger = LoggerFactory.getLogger(DruidMonitorAutoConfiguration.class); 35 | 36 | @Autowired 37 | private DruidMonitorProperties properties; 38 | 39 | /** 40 | * 注册一个StatViewServlet 41 | * 42 | * @return ServletRegistrationBean 43 | */ 44 | @Bean 45 | public ServletRegistrationBean druidStatViewServlet(){ 46 | //org.springframework.boot.context.embedded.ServletRegistrationBean提供类的进行注册. 47 | ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),properties.getDruidStatView()); 48 | 49 | //添加初始化参数:initParams 50 | 51 | //白名单: 52 | servletRegistrationBean.addInitParameter("allow",properties.getAllow()); 53 | logger.info("allow ---> " + properties.getAllow()); 54 | //IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page. 55 | servletRegistrationBean.addInitParameter("deny",properties.getDeny()); 56 | logger.info("deny ---> " + properties.getDeny()); 57 | //登录查看信息的账号密码. 58 | servletRegistrationBean.addInitParameter("loginUsername",properties.getLoginUsername()); 59 | servletRegistrationBean.addInitParameter("loginPassword",properties.getLoginPassword()); 60 | logger.info("loginUsername ---> " + properties.getLoginUsername() + "loginPassword ---> " + properties.getLoginPassword()); 61 | //是否能够重置数据. 62 | servletRegistrationBean.addInitParameter("resetEnable",properties.getResetEnable()); 63 | logger.info("resetEnable ---> " + properties.getResetEnable()); 64 | return servletRegistrationBean; 65 | } 66 | 67 | /** 68 | * 注册一个:filterRegistrationBean 69 | * 70 | * @return FilterRegistrationBean 71 | */ 72 | @Bean 73 | public FilterRegistrationBean druidStatFilter(){ 74 | 75 | FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter()); 76 | 77 | //添加过滤规则. 78 | filterRegistrationBean.addUrlPatterns(properties.getDruidWebStatFilter()); 79 | logger.info("urlPatterns ---> " + properties.getDruidWebStatFilter()); 80 | 81 | //添加不需要忽略的格式信息. 82 | filterRegistrationBean.addInitParameter("exclusions",properties.getExclusions()); 83 | logger.info("exclusions ---> " + properties.getExclusions()); 84 | return filterRegistrationBean; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/cn/binux/druid/DruidMonitorProperties.java: -------------------------------------------------------------------------------- 1 | package cn.binux.druid; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | /** 6 | * Druid配置 7 | * 8 | * @author xubin. 9 | * @create 2017-04-06 10 | */ 11 | 12 | @ConfigurationProperties(prefix = "druid.monitor") 13 | public class DruidMonitorProperties { 14 | 15 | private String DruidStatView; 16 | private String DruidWebStatFilter; 17 | 18 | private String allow; 19 | private String deny; 20 | private String loginUsername; 21 | private String loginPassword; 22 | 23 | private String exclusions; 24 | private String resetEnable; 25 | 26 | public String getDruidStatView() { 27 | return DruidStatView; 28 | } 29 | 30 | public void setDruidStatView(String druidStatView) { 31 | DruidStatView = druidStatView; 32 | } 33 | 34 | public String getDruidWebStatFilter() { 35 | return DruidWebStatFilter; 36 | } 37 | 38 | public void setDruidWebStatFilter(String druidWebStatFilter) { 39 | DruidWebStatFilter = druidWebStatFilter; 40 | } 41 | 42 | public String getAllow() { 43 | return allow; 44 | } 45 | 46 | public void setAllow(String allow) { 47 | this.allow = allow; 48 | } 49 | 50 | public String getDeny() { 51 | return deny; 52 | } 53 | 54 | public void setDeny(String deny) { 55 | this.deny = deny; 56 | } 57 | 58 | public String getLoginUsername() { 59 | return loginUsername; 60 | } 61 | 62 | public void setLoginUsername(String loginUsername) { 63 | this.loginUsername = loginUsername; 64 | } 65 | 66 | public String getLoginPassword() { 67 | return loginPassword; 68 | } 69 | 70 | public void setLoginPassword(String loginPassword) { 71 | this.loginPassword = loginPassword; 72 | } 73 | 74 | public String getExclusions() { 75 | return exclusions; 76 | } 77 | 78 | public void setExclusions(String exclusions) { 79 | this.exclusions = exclusions; 80 | } 81 | 82 | public String getResetEnable() { 83 | return resetEnable; 84 | } 85 | 86 | public void setResetEnable(String resetEnable) { 87 | this.resetEnable = resetEnable; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/cn/binux/druid/DruidProperties.java: -------------------------------------------------------------------------------- 1 | package cn.binux.druid; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | /** 6 | * Druid配置 7 | * 8 | * @author xubin. 9 | * @create 2017-04-05 10 | */ 11 | 12 | @ConfigurationProperties(prefix = "druid") 13 | public class DruidProperties { 14 | 15 | private String url; 16 | private String username; 17 | private String password; 18 | private String driverClass; 19 | private String filters; 20 | private String connectionProperties; 21 | private String validationQuery; 22 | 23 | private Boolean testWhileIdle; 24 | private Boolean testOnBorrow; 25 | private Boolean testOnReturn; 26 | private Boolean poolPreparedStatements; 27 | 28 | private Integer maxWait; 29 | private Integer maxActive; 30 | private Integer minIdle; 31 | private Integer initialSize; 32 | private Integer timeBetweenEvictionRunsMillis; 33 | private Integer minEvictableIdleTimeMillis; 34 | private Integer maxPoolPreparedStatementPerConnectionSize; 35 | 36 | public String getUrl() { 37 | return url; 38 | } 39 | 40 | public void setUrl(String url) { 41 | this.url = url; 42 | } 43 | 44 | public String getUsername() { 45 | return username; 46 | } 47 | 48 | public void setUsername(String username) { 49 | this.username = username; 50 | } 51 | 52 | public String getPassword() { 53 | return password; 54 | } 55 | 56 | public void setPassword(String password) { 57 | this.password = password; 58 | } 59 | 60 | public String getDriverClass() { 61 | return driverClass; 62 | } 63 | 64 | public void setDriverClass(String driverClass) { 65 | this.driverClass = driverClass; 66 | } 67 | 68 | public String getFilters() { 69 | return filters; 70 | } 71 | 72 | public void setFilters(String filters) { 73 | this.filters = filters; 74 | } 75 | 76 | public String getConnectionProperties() { 77 | return connectionProperties; 78 | } 79 | 80 | public void setConnectionProperties(String connectionProperties) { 81 | this.connectionProperties = connectionProperties; 82 | } 83 | 84 | public String getValidationQuery() { 85 | return validationQuery; 86 | } 87 | 88 | public void setValidationQuery(String validationQuery) { 89 | this.validationQuery = validationQuery; 90 | } 91 | 92 | public Boolean getTestWhileIdle() { 93 | return testWhileIdle; 94 | } 95 | 96 | public void setTestWhileIdle(Boolean testWhileIdle) { 97 | this.testWhileIdle = testWhileIdle; 98 | } 99 | 100 | public Boolean getTestOnBorrow() { 101 | return testOnBorrow; 102 | } 103 | 104 | public void setTestOnBorrow(Boolean testOnBorrow) { 105 | this.testOnBorrow = testOnBorrow; 106 | } 107 | 108 | public Boolean getTestOnReturn() { 109 | return testOnReturn; 110 | } 111 | 112 | public void setTestOnReturn(Boolean testOnReturn) { 113 | this.testOnReturn = testOnReturn; 114 | } 115 | 116 | public Boolean getPoolPreparedStatements() { 117 | return poolPreparedStatements; 118 | } 119 | 120 | public void setPoolPreparedStatements(Boolean poolPreparedStatements) { 121 | this.poolPreparedStatements = poolPreparedStatements; 122 | } 123 | 124 | public Integer getMaxWait() { 125 | return maxWait; 126 | } 127 | 128 | public void setMaxWait(Integer maxWait) { 129 | this.maxWait = maxWait; 130 | } 131 | 132 | public Integer getMaxActive() { 133 | return maxActive; 134 | } 135 | 136 | public void setMaxActive(Integer maxActive) { 137 | this.maxActive = maxActive; 138 | } 139 | 140 | public Integer getMinIdle() { 141 | return minIdle; 142 | } 143 | 144 | public void setMinIdle(Integer minIdle) { 145 | this.minIdle = minIdle; 146 | } 147 | 148 | public Integer getInitialSize() { 149 | return initialSize; 150 | } 151 | 152 | public void setInitialSize(Integer initialSize) { 153 | this.initialSize = initialSize; 154 | } 155 | 156 | public Integer getTimeBetweenEvictionRunsMillis() { 157 | return timeBetweenEvictionRunsMillis; 158 | } 159 | 160 | public void setTimeBetweenEvictionRunsMillis(Integer timeBetweenEvictionRunsMillis) { 161 | this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; 162 | } 163 | 164 | public Integer getMinEvictableIdleTimeMillis() { 165 | return minEvictableIdleTimeMillis; 166 | } 167 | 168 | public void setMinEvictableIdleTimeMillis(Integer minEvictableIdleTimeMillis) { 169 | this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; 170 | } 171 | 172 | public Integer getMaxPoolPreparedStatementPerConnectionSize() { 173 | return maxPoolPreparedStatementPerConnectionSize; 174 | } 175 | 176 | public void setMaxPoolPreparedStatementPerConnectionSize(Integer maxPoolPreparedStatementPerConnectionSize) { 177 | this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize; 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | cn.binux.druid.DruidAutoConfiguration,\ 3 | cn.binux.druid.DruidMonitorAutoConfiguration --------------------------------------------------------------------------------