├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── druid-spring-boot-autoconfigure
├── build.gradle
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── cuisongliu
│ │ └── druid
│ │ └── autoconfigure
│ │ ├── DruidAutoConfiguration.java
│ │ ├── DruidFilterAutoConfiguration.java
│ │ ├── DruidServletAutoConfiguration.java
│ │ ├── condition
│ │ ├── AopTypesCondition.java
│ │ ├── AopTypesInitCondition.java
│ │ ├── ConditionUtil.java
│ │ ├── NameAopTypesCondition.java
│ │ ├── PointcutAopTypesCondition.java
│ │ └── TypeAopTypesCondition.java
│ │ ├── properties
│ │ ├── DruidFilterProperties.java
│ │ ├── DruidProperties.java
│ │ └── DruidServletProperties.java
│ │ └── stat
│ │ ├── DruidNameAopAutoConfiguration.java
│ │ ├── DruidPointcutAopAutoConfiguration.java
│ │ ├── DruidStatAutoConfiguration.java
│ │ ├── DruidStatInitAutoConfiguration.java
│ │ ├── DruidStatProperties.java
│ │ └── DruidTypeAopAutoConfiguration.java
│ └── resources
│ └── META-INF
│ └── spring.factories
├── druid-spring-boot-starter
├── build.gradle
└── src
│ └── main
│ └── resources
│ └── META-INF
│ └── spring.provides
├── gradle
├── allproject.gradle
├── extra
│ ├── compile.gradle
│ ├── ext.gradle
│ ├── pack.gradle
│ └── plugins.gradle
├── subprojects.gradle
└── subprojects
│ ├── druid-spring-boot-autoconfigure.gradle
│ └── druid-spring-boot-starter.gradle
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # IDEA #
2 | .idea/
3 | *.iml
4 | out/
5 |
6 | # Gradle #
7 | .gradle/
8 | springboot/build
9 | build/
10 |
11 | # Ignore Gradle GUI config
12 | gradle-app.setting
13 |
14 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
15 | !gradle-wrapper.jar
16 |
17 | # Cache of project
18 | .gradletasknamecache
19 |
20 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
21 | gradle/wrapper/gradle-wrapper.properties
22 | gradle/wrapper/gradle-wrapper.jar
23 |
24 |
25 | # Eclipse #
26 | .settings/
27 | .classpath
28 | .project
29 |
30 | # jrebel #
31 | src/main/resources/rebel.xml
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 cuisongliu
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/cuisongliu/druid-boot-starter)
2 | [](https://www.versioneye.com/user/projects/5918687ae1638f0051a0a62c)
3 | [](https://gradle.org)
4 | [](https://opensource.org/licenses/mit-license.php)
5 |
6 | # [Druid](https://github.com/alibaba/druid) integration with springboot
7 |
8 | Druid-Spring-Boot-Starter 帮助你集成通用 [Druid](https://github.com/alibaba/druid) 到 Spring Boot。
9 |
10 | Druid-Spring-Boot-Starter will help you use [Druid](https://github.com/alibaba/druid) with Spring Boot.
11 |
12 | ## How to use
13 |
14 | ### maven
15 |
16 | 在pom.xml加入nexus资源库(解决中国访问慢的问题,已经加入中央仓库)
17 |
18 | Add the following nexus repository(fix china access slow problem,already append to central nexus.) to your pom.xml:
19 |
20 |
21 |
22 | nexus
23 | nexus
24 | http://maven.cuisongliu.com/content/groups/public
25 |
26 | true
27 |
28 |
29 | false
30 |
31 |
32 |
33 |
34 | 在pom.xml加入依赖
35 |
36 | Add the following dependency to your pom.xml:
37 |
38 |
39 | com.alibaba
40 | druid
41 | 1.1.5
42 |
43 |
44 | com.cuisongliu
45 | druid-spring-boot-starter
46 | 1.3
47 |
48 |
49 | ### gradle
50 |
51 | 在build.gradle加入nexus资源库(解决中国访问慢的问题,已经加入中央仓库)
52 |
53 | Add the following nexus repository(fix china access slow problem,already append to central nexus.) to your build.gradle:
54 |
55 | allprojects {
56 | repositories {
57 | mavenLocal()
58 | maven { url "http://maven.cuisongliu.com/content/groups/public" }
59 | mavenCentral()
60 | jcenter()
61 | }
62 | }
63 |
64 | 在build.gradle加入依赖
65 |
66 | Add the following dependency to your build.gradle:
67 |
68 | compile "com.alibaba:druid:1+"
69 | compile "com.cuisongliu:druid-spring-boot-starter:1+"
70 |
71 | ### springboot properties set
72 |
73 | 在application.properties 或者application.yml加入[相关参数](https://github.com/alibaba/druid/wiki/DruidDataSource%E9%85%8D%E7%BD%AE%E5%B1%9E%E6%80%A7%E5%88%97%E8%A1%A8)
74 |
75 | at application.properties or application.yml append some properties.
76 |
77 | | properties | IsNull? | Defaults |
78 | | :------|:------|:------|
79 | |spring.datasource.url|no|null|
80 | |spring.datasource.username|no|null|
81 | |spring.datasource.password|no|null|
82 | |spring.datasource.druid.max-active|yes|8|
83 | |spring.datasource.druid.min-idle|yes|0|
84 | |spring.datasource.druid.initial-size|yes|0|
85 | |spring.datasource.druid.max-wait|yes|-1|
86 | |spring.datasource.druid.time-between-eviction-runs-millis|yes|60 * 1000L|
87 | |spring.datasource.druid.max-open-prepared-statements|yes|-1|
88 | |spring.datasource.druid.test-on-borrow|yes|false|
89 | |spring.datasource.druid.validation-query|yes|null|
90 | |spring.datasource.druid.test-on-return|yes|false|
91 | |spring.datasource.druid.test-while-idle|yes|true|
92 | |spring.datasource.druid.pool-prepared-statements|yes|false|
93 | |spring.datasource.druid.filters|yes|false|
94 | |spring.datasource.druid.max-pool-prepared-statement-per-connection-size|yes|-1|
95 | |spring.datasource.druid.validation-query-timeout|yes|-1|
96 | |spring.datasource.druid.min-evictable-idle-time-millis|yes|1000L * 60L * 30L|
97 | |spring.datasource.druid.connection-properties|yes|null|
98 |
99 | sql slow config:
100 |
101 | spring:
102 | datasource:
103 | druid:
104 | connection-properties:
105 | - druid.stat.mergeSql=true
106 | - druid.stat.slowSqlMillis=5000
107 |
108 | [servlet properties](https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_StatViewServlet%E9%85%8D%E7%BD%AE)
109 |
110 | | properties | IsNull? | Defaults |
111 | | :------|:------|:------|
112 | |spring.datasource.druid.servlet.enable|yes|true|
113 | |spring.datasource.druid.servlet.url-mappings|yes|/druid/*|
114 | |spring.datasource.druid.servlet.allow|yes|null|
115 | |spring.datasource.druid.servlet.deny|yes|null|
116 | |spring.datasource.druid.servlet.login-username|yes|null|
117 | |spring.datasource.druid.servlet.login-password|yes|null|
118 | |spring.datasource.druid.servlet.reset-enable|yes|null|
119 |
120 | [filter properties](https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_%E9%85%8D%E7%BD%AEWebStatFilter)
121 |
122 | | properties | IsNull? | Defaults |
123 | | :------|:------|:------|
124 | |spring.datasource.druid.servlet.enable|yes|false|
125 | |spring.datasource.druid.servlet.exclusions|yes|*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*|
126 | |spring.datasource.druid.servlet.url-pattern|yes|/*|
127 | |spring.datasource.druid.servlet.session-stat-max-count|yes|1000|
128 | |spring.datasource.druid.servlet.session-stat-enable|yes|false|
129 | |spring.datasource.druid.servlet.principal-session-name|yes|USER_SESSION|
130 | |spring.datasource.druid.servlet.principal-cookie-name|yes|USER_COOKIE|
131 | |spring.datasource.druid.servlet.profile-enable|yes|true|
132 |
133 | [stat properties](https://github.com/alibaba/druid/wiki/%E9%85%8D%E7%BD%AE_Druid%E5%92%8CSpring%E5%85%B3%E8%81%94%E7%9B%91%E6%8E%A7%E9%85%8D%E7%BD%AE)
134 |
135 | | properties | IsNull? | Defaults |
136 | | :------|:------|:------|
137 | |spring.datasource.druid.stat.enable|yes|false|
138 | |spring.datasource.druid.stat.aop-types|yes|null|
139 | |spring.datasource.druid.stat.target-bean-type|yes|null|
140 | |spring.datasource.druid.stat.bean-names|yes|null|
141 | /spring.datasource.druid.stat.patterns|yes|null|
142 |
143 | spring.datasource.druid.stat.aop-types 待选值有[ ***type,name,pointcut*** ]
144 |
145 | 当enable=true时候,aop-types必须有type或者name的其中一项.
146 |
147 | - 当aop-types有name值时,bean-names不能为空.
148 | - 当aop-types有type值时,target-bean-type不能为空.
149 | - 当aop-types有pointcut值时,patterns不能为空.
150 |
151 | spring.datasource.druid.stat.aop-types selected value is [ ***type,name,pointcut*** ]
152 |
153 |
154 | When ```enable=true``` , aop-types must have either ```type``` or ```name```.
155 |
156 | - When ```aop-types``` has ```name``` value, ```bean-names``` can not be null.
157 | - When ```aop-types``` have ```type``` values, ```target-bean-type``` can not be empty.
158 | - When ```aop-types``` have ```pointcut``` values, ```patterns``` can not be empty.
159 |
160 | ## Example
161 |
162 |
163 | spring:
164 | datasource:
165 | url: xxx
166 | username: xxx
167 | password: xxx
168 | druid:
169 | filters: stat,wall,log4j
170 | connection-properties:
171 | - druid.stat.mergeSql=true
172 | - druid.stat.slowSqlMillis=5000
173 | filter:
174 | enable: true
175 | principal-session-name: session_admin
176 | profile-enable: true
177 | principal-cookie-name: session_admin
178 | session-stat-enable: true
179 | stat:
180 | enable: true
181 | aop-type:
182 | - name
183 | - type
184 | - pointcut
185 | target-bean-type: com.cuisongliu.springboot.core.mapper.MyMapper
186 | bean-names:
187 | - UserMapper
188 | - userMapper
189 | patterns:
190 | - com.xinyuewulian.mapper.*
191 | - com.xinyuewulian.service.*
192 |
193 | ## Acknowledgments
194 |
195 | [druid](https://github.com/alibaba/druid).
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | plugins {
25 | id "io.codearte.nexus-staging" version "0.8.0"
26 | }
27 | apply from: "$rootDir/gradle/allproject.gradle"
28 | apply from: "$rootDir/gradle/subprojects.gradle"
29 | task printEnv {
30 | println "当前的工程名称为:[$project.name]"
31 | repositories.each {
32 | println "repository: ${it.name} ('${it.url}')"
33 | }
34 | }
35 |
36 | task clean(type: Delete) {
37 | delete rootProject.buildDir
38 | }
39 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | apply from: "$rootDir/gradle/subprojects/druid-spring-boot-autoconfigure.gradle"
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/DruidAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure;
25 |
26 | import com.alibaba.druid.pool.DruidDataSource;
27 | import com.cuisongliu.druid.autoconfigure.properties.DruidProperties;
28 | import com.cuisongliu.druid.autoconfigure.stat.DruidStatAutoConfiguration;
29 | import org.springframework.beans.factory.annotation.Value;
30 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
31 | import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
32 | import org.springframework.boot.context.properties.ConfigurationProperties;
33 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
34 | import org.springframework.context.annotation.Bean;
35 | import org.springframework.context.annotation.Configuration;
36 | import org.springframework.context.annotation.Import;
37 |
38 | import javax.sql.DataSource;
39 | import java.sql.SQLException;
40 |
41 | /**
42 | * druid auto config
43 | * @author cuisongliu
44 | * @since 2017/2/5.
45 | */
46 | @Configuration
47 | @EnableConfigurationProperties(DruidProperties.class)
48 | @ConditionalOnClass(DruidDataSource.class)
49 | @Import({DruidServletAutoConfiguration.class,DruidFilterAutoConfiguration.class, DruidStatAutoConfiguration.class})
50 | public class DruidAutoConfiguration {
51 | @Value("${spring.datasource.url}")
52 | private String url;
53 | @Value("${spring.datasource.username}")
54 | private String username;
55 | @Value("${spring.datasource.password}")
56 | private String password;
57 |
58 | @Bean
59 | @ConfigurationProperties(DruidProperties.DRUID_PREFIX)
60 | public DataSource dataSource(DruidProperties properties) {
61 | DruidDataSource datasource = (DruidDataSource) DataSourceBuilder
62 | .create()
63 | .type(DruidDataSource.class)
64 | .build();
65 | configDruid(datasource, properties);
66 | return datasource;
67 | }
68 |
69 | private void configDruid(DruidDataSource dataSource, DruidProperties properties) {
70 | dataSource.setUrl(url);
71 | dataSource.setUsername(username);
72 | dataSource.setPassword(password);
73 | if (properties.getInitialSize() > 0) {
74 | dataSource.setInitialSize(properties.getInitialSize());
75 | }
76 | if (properties.getMinIdle() > 0) {
77 | dataSource.setMinIdle(properties.getMinIdle());
78 | }
79 | if (properties.getMaxActive() > 0) {
80 | dataSource.setMaxActive(properties.getMaxActive());
81 | }
82 | if (properties.getMaxWait() > 0 ){
83 | dataSource.setMaxWait(properties.getMaxWait());
84 | }
85 | if (properties.getTimeBetweenEvictionRunsMillis() > 0l){
86 | dataSource.setTimeBetweenEvictionRunsMillis(properties.getTimeBetweenEvictionRunsMillis());
87 | }
88 | if (properties.getMaxPoolPreparedStatementPerConnectionSize() > 0 ){
89 | dataSource.setMaxPoolPreparedStatementPerConnectionSize(properties.getMaxPoolPreparedStatementPerConnectionSize());
90 | }
91 | if (properties.getValidationQueryTimeout() > 0 ){
92 | dataSource.setValidationQueryTimeout(properties.getValidationQueryTimeout());
93 | }
94 | if (properties.getMinEvictableIdleTimeMillis() > 0l){
95 | dataSource.setMinEvictableIdleTimeMillis(properties.getMinEvictableIdleTimeMillis());
96 | }
97 | dataSource.setValidationQuery(properties.getValidationQuery());
98 | dataSource.setTestOnReturn(properties.getTestOnReturn());
99 | dataSource.setTestOnBorrow(properties.isTestOnBorrow());
100 | dataSource.setTestWhileIdle(properties.getTestWhileIdle());
101 | dataSource.setPoolPreparedStatements(properties.getPoolPreparedStatements());
102 | dataSource.setConnectProperties(properties.getConnectionProperties());
103 | try {
104 | dataSource.setFilters(properties.getFilters());
105 | } catch (SQLException e) {
106 | throw new IllegalArgumentException("please check your spring.datasource.druid.filters property.", e);
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/DruidFilterAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure;
25 |
26 | import com.alibaba.druid.support.http.WebStatFilter;
27 | import com.cuisongliu.druid.autoconfigure.properties.DruidFilterProperties;
28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
29 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
30 | import org.springframework.boot.context.properties.ConfigurationProperties;
31 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
32 | import org.springframework.boot.web.servlet.FilterRegistrationBean;
33 | import org.springframework.context.annotation.Bean;
34 | /**
35 | * druid filter auto config
36 | * @author cuisongliu
37 | * @since 2017/2/5.
38 | */
39 | @ConditionalOnWebApplication
40 | @EnableConfigurationProperties(DruidFilterProperties.class)
41 | @ConditionalOnProperty(name = DruidFilterProperties.DRUID_FILTER_PREFIX+".enable", havingValue = "true")
42 | public class DruidFilterAutoConfiguration {
43 |
44 | @Bean
45 | @ConfigurationProperties(DruidFilterProperties.DRUID_FILTER_PREFIX)
46 | public FilterRegistrationBean druidFilter(DruidFilterProperties properties) {
47 | FilterRegistrationBean registration = new FilterRegistrationBean();
48 | WebStatFilter filter = new WebStatFilter();
49 | registration.setFilter(filter);
50 | registration.addUrlPatterns(properties.getUrlPattern());
51 | registration.addInitParameter("exclusions",properties.getExclusions());
52 | registration.addInitParameter("sessionStatMaxCount",properties.getSessionStatMaxCount().toString());
53 | registration.addInitParameter("sessionStatEnable",properties.getSessionStatEnable().toString());
54 | registration.addInitParameter("principalSessionName",properties.getPrincipalSessionName());
55 | registration.addInitParameter("principalCookieName",properties.getPrincipalCookieName());
56 | registration.addInitParameter("profileEnable",properties.getProfileEnable().toString());
57 | return registration;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/DruidServletAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure;
25 |
26 | import com.alibaba.druid.support.http.StatViewServlet;
27 | import com.cuisongliu.druid.autoconfigure.properties.DruidServletProperties;
28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
29 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
30 | import org.springframework.boot.context.properties.ConfigurationProperties;
31 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
32 | import org.springframework.boot.web.servlet.ServletRegistrationBean;
33 | import org.springframework.context.annotation.Bean;
34 |
35 |
36 | /**
37 | * druid servlet auto config
38 | * @author cuisongliu
39 | * @since 2017/5/18
40 | */
41 | @ConditionalOnWebApplication
42 | @EnableConfigurationProperties(DruidServletProperties.class)
43 | @ConditionalOnProperty(name =DruidServletProperties.DRUID_SERVLET_PREFIX+ ".enable", havingValue = "true", matchIfMissing = true)
44 | public class DruidServletAutoConfiguration {
45 |
46 | @Bean
47 | @ConfigurationProperties(DruidServletProperties.DRUID_SERVLET_PREFIX)
48 | public ServletRegistrationBean druidServlet(DruidServletProperties properties) {
49 | ServletRegistrationBean reg = new ServletRegistrationBean();
50 | reg.setServlet(new StatViewServlet());
51 | reg.addUrlMappings(properties.getUrlMappings());
52 | if(properties.getAllow() !=null){
53 | reg.addInitParameter("allow", properties.getAllow()); // IP白名单 (没有配置或者为空,则允许所有访问)
54 | }
55 | if(properties.getDeny() !=null){
56 | reg.addInitParameter("deny", properties.getDeny()); //IP黑名单 (存在共同时,deny优先于allow)
57 | }
58 | if(properties.getLoginUsername() !=null){
59 | reg.addInitParameter("loginUsername", properties.getLoginUsername()); //用户名
60 | }
61 | if(properties.getLoginPassword() !=null){
62 | reg.addInitParameter("loginPassword", properties.getLoginPassword()); // 密码
63 | }
64 | if(properties.getResetEnable() !=null){
65 | reg.addInitParameter("resetEnable", properties.getResetEnable().toString());// 禁用HTML页面上的“Reset All”功能
66 | }
67 | return reg;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/condition/AopTypesCondition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.condition;
25 |
26 | import com.cuisongliu.druid.autoconfigure.stat.DruidStatProperties;
27 | import org.springframework.boot.context.properties.ConfigurationProperties;
28 | import org.springframework.context.annotation.Condition;
29 | import org.springframework.context.annotation.ConditionContext;
30 | import org.springframework.core.type.AnnotatedTypeMetadata;
31 |
32 | import java.util.List;
33 |
34 | /**
35 | * aop types conditional abstract class
36 | *
37 | * @author cuisongliu [cuisongliu@qq.com]
38 | * @since 2017-05-21 11:32
39 | */
40 | @ConfigurationProperties(DruidStatProperties.DRUID_STAT_PREFIX)
41 | public abstract class AopTypesCondition implements Condition {
42 |
43 | @Override
44 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
45 | List list = ConditionUtil.getInstance().getAopTypesValue(context);
46 | return list.contains(containsValue().getValue());
47 | }
48 |
49 | protected abstract DruidStatProperties.AopType containsValue();
50 | }
51 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/condition/AopTypesInitCondition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.condition;
25 |
26 | import com.cuisongliu.druid.autoconfigure.stat.DruidStatProperties;
27 | import org.springframework.context.annotation.Condition;
28 | import org.springframework.context.annotation.ConditionContext;
29 | import org.springframework.core.type.AnnotatedTypeMetadata;
30 |
31 | import java.util.*;
32 |
33 | /**
34 | * aop types init conditional
35 | *
36 | * @author cuisongliu [cuisongliu@qq.com]
37 | * @since 2017-05-21 11:32
38 | */
39 | public class AopTypesInitCondition implements Condition {
40 |
41 | @Override
42 | public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
43 | List list = ConditionUtil.getInstance().getAopTypesValue(context);
44 | if (list.contains(DruidStatProperties.AopType.type.getValue())||
45 | list.contains(DruidStatProperties.AopType.name.getValue()) ||
46 | list.contains(DruidStatProperties.AopType.pointcut.getValue())) {
47 | return true;
48 | } else {
49 | throw new IllegalStateException(DruidStatProperties.DRUID_STAT_PREFIX + ".aop-types must has [ " +
50 | DruidStatProperties.AopType.type.getValue() + "," +
51 | DruidStatProperties.AopType.name.getValue() + "," +
52 | DruidStatProperties.AopType.pointcut.getValue() + " " +
53 | "]");
54 | }
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/condition/ConditionUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.condition;
25 |
26 | import com.cuisongliu.druid.autoconfigure.stat.DruidStatProperties;
27 | import org.springframework.context.annotation.ConditionContext;
28 | import org.springframework.util.StringUtils;
29 |
30 | import java.util.ArrayList;
31 | import java.util.LinkedHashSet;
32 | import java.util.List;
33 | import java.util.Set;
34 |
35 | /**
36 | * about condition util for aop types
37 | *
38 | * @author cuisongliu [cuisongliu@qq.com]
39 | * @since 2017-05-21 12:43
40 | */
41 | class ConditionUtil {
42 | private static ConditionUtil instance = new ConditionUtil();
43 |
44 | static ConditionUtil getInstance() {
45 | if (instance == null)
46 | instance = new ConditionUtil();
47 | return instance;
48 | }
49 |
50 | private ConditionUtil() {
51 | }
52 |
53 | List getAopTypesValue(ConditionContext context){
54 | String aopTypesKey = DruidStatProperties.DRUID_STAT_PREFIX+".aop-types";
55 | Set keySet = new LinkedHashSet();
56 | for (int i = 0; i <3 ; i++) {
57 | String field = context.getEnvironment().getProperty(aopTypesKey+"["+i+"]", String.class);
58 | if (!StringUtils.isEmpty(field))
59 | keySet.add(field.toLowerCase());
60 | }
61 | if (keySet.size() > 0 ){
62 | return new ArrayList(keySet);
63 | }else {
64 | return new ArrayList();
65 | }
66 |
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/condition/NameAopTypesCondition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.condition;
25 |
26 | import com.cuisongliu.druid.autoconfigure.stat.DruidStatProperties;
27 |
28 | /**
29 | * name aop types conditional
30 | *
31 | * @author cuisongliu [cuisongliu@qq.com]
32 | * @since 2017-05-21 11:47
33 | */
34 | public class NameAopTypesCondition extends AopTypesCondition {
35 |
36 | @Override
37 | protected DruidStatProperties.AopType containsValue() {
38 | return DruidStatProperties.AopType.name;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/condition/PointcutAopTypesCondition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.condition;
25 |
26 | import com.cuisongliu.druid.autoconfigure.stat.DruidStatProperties;
27 |
28 | /**
29 | * name aop types conditional
30 | *
31 | * @author cuisongliu [cuisongliu@qq.com]
32 | * @since 2017-05-21 11:47
33 | */
34 | public class PointcutAopTypesCondition extends AopTypesCondition {
35 |
36 | @Override
37 | protected DruidStatProperties.AopType containsValue() {
38 | return DruidStatProperties.AopType.pointcut;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/condition/TypeAopTypesCondition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.condition;
25 |
26 | import com.cuisongliu.druid.autoconfigure.stat.DruidStatProperties;
27 |
28 | /**
29 | * name aop types conditional
30 | *
31 | * @author cuisongliu [cuisongliu@qq.com]
32 | * @since 2017-05-21 11:47
33 | */
34 | public class TypeAopTypesCondition extends AopTypesCondition {
35 |
36 | @Override
37 | protected DruidStatProperties.AopType containsValue() {
38 | return DruidStatProperties.AopType.type;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/properties/DruidFilterProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.properties;
25 |
26 | import org.springframework.boot.context.properties.ConfigurationProperties;
27 |
28 | /**
29 | * druid filter properties
30 | * @author cuisongliu
31 | * @since 2017/2/5.
32 | */
33 | @ConfigurationProperties(prefix = DruidFilterProperties.DRUID_FILTER_PREFIX)
34 | public class DruidFilterProperties {
35 | public static final String DRUID_FILTER_PREFIX = DruidProperties.DRUID_PREFIX+".filter";
36 | /**
37 | * 是否加入druid拦截器,默认为false
38 | */
39 | private Boolean enable = false;
40 | /**
41 | * 拦截资源排除,默认为'*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*'
42 | */
43 | private String exclusions = "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*";
44 | /**
45 | * 需要拦截的Url,默认为'/*'
46 | */
47 | private String urlPattern = "/*";
48 | /**
49 | * 缺省sessionStatMaxCount是1000个。你可以按需要进行配置
50 | */
51 | private Integer sessionStatMaxCount = 1000;
52 | /**
53 | * session统计功能,默认为false
54 | */
55 | private Boolean sessionStatEnable = false;
56 | /**
57 | * 使得druid能够知道当前的session的用户是谁,默认为USER_SESSION
58 | */
59 | private String principalSessionName = "USER_SESSION";
60 | /**
61 | * 使得druid能够知道当前的cookie的用户是谁,默认为USER_COOKIE
62 | */
63 | private String principalCookieName = "USER_COOKIE";
64 | /**
65 | * profileEnable能够监控单个url调用的sql,,默认为true
66 | */
67 | private Boolean profileEnable = true;
68 |
69 | public Boolean getEnable() {
70 | return enable;
71 | }
72 |
73 | public void setEnable(Boolean enable) {
74 | this.enable = enable;
75 | }
76 |
77 | public String getExclusions() {
78 | return exclusions;
79 | }
80 |
81 | public void setExclusions(String exclusions) {
82 | this.exclusions = exclusions;
83 | }
84 |
85 | public String getUrlPattern() {
86 | return urlPattern;
87 | }
88 |
89 | public void setUrlPattern(String urlPattern) {
90 | this.urlPattern = urlPattern;
91 | }
92 |
93 | public Integer getSessionStatMaxCount() {
94 | return sessionStatMaxCount;
95 | }
96 |
97 | public void setSessionStatMaxCount(Integer sessionStatMaxCount) {
98 | this.sessionStatMaxCount = sessionStatMaxCount;
99 | }
100 |
101 | public Boolean getSessionStatEnable() {
102 | return sessionStatEnable;
103 | }
104 |
105 | public void setSessionStatEnable(Boolean sessionStatEnable) {
106 | this.sessionStatEnable = sessionStatEnable;
107 | }
108 |
109 | public String getPrincipalSessionName() {
110 | return principalSessionName;
111 | }
112 |
113 | public void setPrincipalSessionName(String principalSessionName) {
114 | this.principalSessionName = principalSessionName;
115 | }
116 |
117 | public String getPrincipalCookieName() {
118 | return principalCookieName;
119 | }
120 |
121 | public void setPrincipalCookieName(String principalCookieName) {
122 | this.principalCookieName = principalCookieName;
123 | }
124 |
125 | public Boolean getProfileEnable() {
126 | return profileEnable;
127 | }
128 |
129 | public void setProfileEnable(Boolean profileEnable) {
130 | this.profileEnable = profileEnable;
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/properties/DruidProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.properties;
25 |
26 | import com.alibaba.druid.pool.DruidAbstractDataSource;
27 | import org.springframework.boot.context.properties.ConfigurationProperties;
28 |
29 | import java.util.Properties;
30 |
31 | /**
32 | * druid数据源的基础属性
33 | *
34 | * @author cuijinrui
35 | * @since 2017/5/14
36 | */
37 | @ConfigurationProperties(prefix = DruidProperties.DRUID_PREFIX)
38 | public class DruidProperties {
39 | public static final String DRUID_PREFIX = "spring.datasource.druid";
40 | /**
41 | * 初始化时建立物理连接的个数。默认为0
42 | * 初始化发生在显示调用init方法,或者第一次getConnection时
43 | */
44 | private int initialSize = DruidAbstractDataSource.DEFAULT_INITIAL_SIZE;
45 | /**
46 | * 最大连接池数量, 默认为8
47 | */
48 | private int maxActive = DruidAbstractDataSource.DEFAULT_MAX_ACTIVE_SIZE;
49 | /**
50 | * 最小连接池数量, 默认为0
51 | */
52 | private int minIdle = DruidAbstractDataSource.DEFAULT_MIN_IDLE;
53 | /**
54 | * 获取连接时最大等待时间,单位毫秒。默认为-1
55 | * 配置了maxWait之后,缺省启用公平锁,并发效率会有所下降,
56 | * 如果需要可以通过配置useUnfairLock属性为true使用非公平锁。
57 | */
58 | private int maxWait = DruidAbstractDataSource.DEFAULT_MAX_WAIT;
59 | /**
60 | * 是否缓存preparedStatement,也就是PSCache。默认为false
61 | * PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭。
62 | */
63 | private Boolean poolPreparedStatements = false;
64 | /**
65 | * 要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。
66 | * 在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100
67 | * 默认为 -1
68 | */
69 | private Integer maxPoolPreparedStatementPerConnectionSize = -1;
70 | /**
71 | * 用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。
72 | * 如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用。
73 | */
74 | private String validationQuery = DruidAbstractDataSource.DEFAULT_VALIDATION_QUERY;
75 | /**
76 | * 单位:秒,检测连接是否有效的超时时间。默认为 -1
77 | * 底层调用jdbc Statement对象的void setQueryTimeout(int seconds)方法
78 | */
79 | private Integer validationQueryTimeout = -1;
80 | /**
81 | * 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。默认为false
82 | */
83 | private boolean testOnBorrow = DruidAbstractDataSource.DEFAULT_TEST_ON_BORROW;
84 | /**
85 | * 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。默认为false
86 | */
87 | private Boolean testOnReturn = DruidAbstractDataSource.DEFAULT_TEST_ON_RETURN;
88 | /**
89 | * 建议配置为true,不影响性能,并且保证安全性。默认为true
90 | * 申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
91 | *
92 | */
93 | private Boolean testWhileIdle = DruidAbstractDataSource.DEFAULT_WHILE_IDLE;
94 | /**
95 | * 有两个含义:
96 | * 1) Destroy线程会检测连接的间隔时间,如果连接空闲时间大于等于minEvictableIdleTimeMillis则关闭物理连接。
97 | * 2) testWhileIdle的判断依据,详细看testWhileIdle属性的说明
98 | * 默认为60000L
99 | */
100 | private Long timeBetweenEvictionRunsMillis = DruidAbstractDataSource.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
101 | /**
102 | * 连接保持空闲而不被驱逐的最长时间.默认为1800000L
103 | */
104 | private Long minEvictableIdleTimeMillis = DruidAbstractDataSource.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
105 |
106 | /**
107 | * 属性类型是字符串,通过别名的方式配置扩展插件,常用的插件有:
108 | * 监控统计用的filter:stat
109 | * 日志用的filter:log4j
110 | * 防御sql注入的filter:wall
111 | */
112 | private String filters = "stat";
113 |
114 | /**
115 | * 额外的属性,例如慢查询等参数.
116 | */
117 | private Properties connectionProperties;
118 |
119 | public Properties getConnectionProperties() {
120 | return connectionProperties;
121 | }
122 |
123 | public void setConnectionProperties(Properties connectionProperties) {
124 | this.connectionProperties = connectionProperties;
125 | }
126 |
127 | public int getMaxActive() {
128 | return maxActive;
129 | }
130 |
131 | public void setMaxActive(int maxActive) {
132 | this.maxActive = maxActive;
133 | }
134 |
135 | public int getMinIdle() {
136 | return minIdle;
137 | }
138 |
139 | public void setMinIdle(int minIdle) {
140 | this.minIdle = minIdle;
141 | }
142 |
143 | public int getInitialSize() {
144 | return initialSize;
145 | }
146 |
147 | public void setInitialSize(int initialSize) {
148 | this.initialSize = initialSize;
149 | }
150 |
151 | public boolean isTestOnBorrow() {
152 | return testOnBorrow;
153 | }
154 |
155 | public void setTestOnBorrow(boolean testOnBorrow) {
156 | this.testOnBorrow = testOnBorrow;
157 | }
158 |
159 | public int getMaxWait() {
160 | return maxWait;
161 | }
162 |
163 | public void setMaxWait(int maxWait) {
164 | this.maxWait = maxWait;
165 | }
166 |
167 | public Long getTimeBetweenEvictionRunsMillis() {
168 | return timeBetweenEvictionRunsMillis;
169 | }
170 |
171 | public void setTimeBetweenEvictionRunsMillis(Long timeBetweenEvictionRunsMillis) {
172 | this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
173 | }
174 |
175 | public String getValidationQuery() {
176 | return validationQuery;
177 | }
178 |
179 | public void setValidationQuery(String validationQuery) {
180 | this.validationQuery = validationQuery;
181 | }
182 |
183 | public Boolean getTestOnReturn() {
184 | return testOnReturn;
185 | }
186 |
187 | public void setTestOnReturn(Boolean testOnReturn) {
188 | this.testOnReturn = testOnReturn;
189 | }
190 |
191 | public Boolean getTestWhileIdle() {
192 | return testWhileIdle;
193 | }
194 |
195 | public void setTestWhileIdle(Boolean testWhileIdle) {
196 | this.testWhileIdle = testWhileIdle;
197 | }
198 |
199 | public Boolean getPoolPreparedStatements() {
200 | return poolPreparedStatements;
201 | }
202 |
203 | public void setPoolPreparedStatements(Boolean poolPreparedStatements) {
204 | this.poolPreparedStatements = poolPreparedStatements;
205 | }
206 |
207 | public Integer getMaxPoolPreparedStatementPerConnectionSize() {
208 | return maxPoolPreparedStatementPerConnectionSize;
209 | }
210 |
211 | public void setMaxPoolPreparedStatementPerConnectionSize(Integer maxPoolPreparedStatementPerConnectionSize) {
212 | this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize;
213 | }
214 |
215 | public Integer getValidationQueryTimeout() {
216 | return validationQueryTimeout;
217 | }
218 |
219 | public void setValidationQueryTimeout(Integer validationQueryTimeout) {
220 | this.validationQueryTimeout = validationQueryTimeout;
221 | }
222 |
223 | public Long getMinEvictableIdleTimeMillis() {
224 | return minEvictableIdleTimeMillis;
225 | }
226 |
227 | public void setMinEvictableIdleTimeMillis(Long minEvictableIdleTimeMillis) {
228 | this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
229 | }
230 |
231 | public String getFilters() {
232 | return filters;
233 | }
234 |
235 | public void setFilters(String filters) {
236 | this.filters = filters;
237 | }
238 |
239 | }
240 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/properties/DruidServletProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.properties;
25 |
26 | import org.springframework.boot.context.properties.ConfigurationProperties;
27 |
28 | /**
29 | * druid servlet properties
30 | * @author cuisongliu
31 | * @since 2017/5/18
32 | */
33 | @ConfigurationProperties(prefix = DruidServletProperties.DRUID_SERVLET_PREFIX)
34 | public class DruidServletProperties {
35 | public static final String DRUID_SERVLET_PREFIX = DruidProperties.DRUID_PREFIX+".servlet";
36 |
37 | /**
38 | * 是否开启druid的监控页面显示,默认为true
39 | */
40 | private Boolean enable = true;
41 | /**
42 | * druid 监控页面的前缀默认为 '/druid/*'
43 | */
44 | private String urlMappings = "/druid/*";
45 | /**
46 | * IP白名单 (没有配置或者为空,则允许所有访问)
47 | */
48 | private String allow;
49 | /**
50 | * IP黑名单 (存在共同时,deny优先于allow)
51 | */
52 | private String deny;
53 | /**
54 | * 用户名
55 | */
56 | private String loginUsername;
57 | /**
58 | * 密码
59 | */
60 | private String loginPassword;
61 | /**
62 | * 禁用HTML页面上的“Reset All”功能 ,默认为false
63 | */
64 | private Boolean resetEnable =false;
65 |
66 | public String getUrlMappings() {
67 | return urlMappings;
68 | }
69 |
70 | public void setUrlMappings(String urlMappings) {
71 | this.urlMappings = urlMappings;
72 | }
73 |
74 | public String getAllow() {
75 | return allow;
76 | }
77 |
78 | public void setAllow(String allow) {
79 | this.allow = allow;
80 | }
81 |
82 | public String getDeny() {
83 | return deny;
84 | }
85 |
86 | public void setDeny(String deny) {
87 | this.deny = deny;
88 | }
89 |
90 | public String getLoginUsername() {
91 | return loginUsername;
92 | }
93 |
94 | public void setLoginUsername(String loginUsername) {
95 | this.loginUsername = loginUsername;
96 | }
97 |
98 | public String getLoginPassword() {
99 | return loginPassword;
100 | }
101 |
102 | public void setLoginPassword(String loginPassword) {
103 | this.loginPassword = loginPassword;
104 | }
105 |
106 | public Boolean getResetEnable() {
107 | return resetEnable;
108 | }
109 |
110 | public void setResetEnable(Boolean resetEnable) {
111 | this.resetEnable = resetEnable;
112 | }
113 |
114 | public Boolean getEnable() {
115 | return enable;
116 | }
117 |
118 | public void setEnable(Boolean enable) {
119 | this.enable = enable;
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/stat/DruidNameAopAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.stat;
25 |
26 | import com.cuisongliu.druid.autoconfigure.condition.NameAopTypesCondition;
27 | import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
28 | import org.springframework.beans.factory.annotation.Value;
29 | import org.springframework.boot.context.properties.ConfigurationProperties;
30 | import org.springframework.context.annotation.Bean;
31 | import org.springframework.context.annotation.Conditional;
32 |
33 | /**
34 | * 按照BeanId来拦截配置stat和spring监控关联
35 | * @author cuisongliu
36 | * @since 2017年5月20日 11:15:26
37 | */
38 | @Conditional(NameAopTypesCondition.class)
39 | public class DruidNameAopAutoConfiguration extends DruidStatInitAutoConfiguration{
40 |
41 | @Value("${spring.aop.proxy-target-class:false}")
42 | private boolean proxyTargetClass;
43 |
44 | @Bean
45 | @ConfigurationProperties(DruidStatProperties.DRUID_STAT_PREFIX)
46 | public BeanNameAutoProxyCreator nameProxyCreator(DruidStatProperties properties){
47 | if (properties.getBeanNames() == null){
48 | throw new IllegalStateException(DruidStatProperties.DRUID_STAT_PREFIX+".bean-names must not null.");
49 | }
50 | BeanNameAutoProxyCreator creator = new BeanNameAutoProxyCreator();
51 | creator.setProxyTargetClass(proxyTargetClass);
52 | String[] beanNames = new String[properties.getBeanNames().size()];
53 | beanNames = properties.getBeanNames().toArray(beanNames);
54 | creator.setBeanNames(beanNames);
55 | creator.setInterceptorNames(DruidStatProperties.DRUID_STAT_INTERCEPTOR_NAME);
56 | return creator;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/stat/DruidPointcutAopAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.stat;
25 |
26 | import com.cuisongliu.druid.autoconfigure.condition.PointcutAopTypesCondition;
27 | import org.springframework.aop.Advisor;
28 | import org.springframework.aop.Pointcut;
29 | import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
30 | import org.springframework.aop.support.DefaultPointcutAdvisor;
31 | import org.springframework.aop.support.JdkRegexpMethodPointcut;
32 | import org.springframework.beans.factory.annotation.Value;
33 | import org.springframework.boot.context.properties.ConfigurationProperties;
34 | import org.springframework.context.annotation.Bean;
35 | import org.springframework.context.annotation.Conditional;
36 |
37 | /**
38 | * 方法名正则匹配拦截配置
39 | *
40 | * @author cuisongliu [cuisongliu@qq.com]
41 | * @since 2017-05-22 10:26
42 | */
43 | @Conditional(PointcutAopTypesCondition.class)
44 | public class DruidPointcutAopAutoConfiguration extends DruidStatInitAutoConfiguration{
45 | @Value("${spring.aop.proxy-target-class:false}")
46 | private boolean proxyTargetClass;
47 |
48 | @Bean
49 | public Pointcut pointcut(DruidStatProperties properties) {
50 | if (properties.getPatterns().length <= 0){
51 | throw new IllegalStateException(DruidStatProperties.DRUID_STAT_PREFIX+".target-bean-type must not null.");
52 | }
53 | JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
54 | pointcut.setPatterns(properties.getPatterns());
55 | return pointcut;
56 | }
57 |
58 | @Bean
59 | public Advisor advisor(DruidStatProperties properties){
60 | return new DefaultPointcutAdvisor(pointcut(properties),druidStatInterceptor());
61 | }
62 |
63 | @Bean
64 | @ConfigurationProperties(DruidStatProperties.DRUID_STAT_PREFIX)
65 | public DefaultAdvisorAutoProxyCreator regexpProxyCreator(DruidStatProperties properties){
66 | DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator();
67 | creator.setProxyTargetClass(proxyTargetClass);
68 | return creator;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/stat/DruidStatAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.stat;
25 |
26 | import com.cuisongliu.druid.autoconfigure.condition.AopTypesInitCondition;
27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
28 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
29 | import org.springframework.context.annotation.Conditional;
30 | import org.springframework.context.annotation.Import;
31 | /**
32 | * stat和spring监控关联主配置
33 | * @author cuisongliu
34 | * @since 2017年5月20日 11:15:26
35 | */
36 | @EnableConfigurationProperties(DruidStatProperties.class)
37 | @ConditionalOnProperty(name = DruidStatProperties.DRUID_STAT_PREFIX +".enable", havingValue = "true")
38 | @Conditional(AopTypesInitCondition.class)
39 | @Import({DruidNameAopAutoConfiguration.class,DruidTypeAopAutoConfiguration.class,DruidPointcutAopAutoConfiguration.class})
40 | public class DruidStatAutoConfiguration {
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/stat/DruidStatInitAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.stat;
25 |
26 | import com.alibaba.druid.support.spring.stat.DruidStatInterceptor;
27 | import org.aopalliance.intercept.Interceptor;
28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
29 | import org.springframework.context.annotation.Bean;
30 |
31 | /**
32 | * stat和spring监控关联的初始化配置
33 | * @author cuisongliu
34 | * @since 2017年5月20日 11:15:26
35 | */
36 | public class DruidStatInitAutoConfiguration {
37 |
38 | @ConditionalOnMissingBean(name = {DruidStatProperties.DRUID_STAT_INTERCEPTOR_NAME})
39 | @Bean(DruidStatProperties.DRUID_STAT_INTERCEPTOR_NAME)
40 | public Interceptor druidStatInterceptor() {
41 | return new DruidStatInterceptor();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/stat/DruidStatProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.stat;
25 |
26 |
27 | import com.cuisongliu.druid.autoconfigure.properties.DruidProperties;
28 | import org.springframework.boot.context.properties.ConfigurationProperties;
29 |
30 | import java.util.ArrayList;
31 | import java.util.List;
32 |
33 | /**
34 | * stat和spring监控关联的参数
35 | *
36 | * @author cuisongliu
37 | * @since 2017年5月20日 11:15:26
38 | */
39 | @ConfigurationProperties(prefix = DruidStatProperties.DRUID_STAT_PREFIX)
40 | public class DruidStatProperties {
41 | public static final String DRUID_STAT_PREFIX = DruidProperties.DRUID_PREFIX + ".stat";
42 | public static final String DRUID_STAT_INTERCEPTOR_NAME = "druid-stat-interceptor";
43 | /**
44 | * druid spring stat是否开启,默认为false
45 | */
46 | private Boolean enable = false;
47 | /**
48 | * aop spring监控类型
49 | */
50 | private List aopTypes = new ArrayList();
51 | /**
52 | * 当aopTypes=type所用 ,监控该抽象类或者接口的所有的实现方法.
53 | */
54 | private Class> targetBeanType;
55 |
56 | /**
57 | * 当aopTypes=name所用,监控所有的beanNames
58 | */
59 | private List beanNames;
60 |
61 | /**
62 | * 当aopTypes=pointcut所用,监控所有的表达式
63 | */
64 | private String[] patterns;
65 |
66 | public List getAopTypes() {
67 | return aopTypes;
68 | }
69 |
70 | public void setAopTypes(List aopTypes) {
71 | this.aopTypes = aopTypes;
72 | }
73 |
74 | public Boolean getEnable() {
75 | return enable;
76 | }
77 |
78 | public void setEnable(Boolean enable) {
79 | this.enable = enable;
80 | }
81 |
82 | public Class> getTargetBeanType() {
83 | return targetBeanType;
84 | }
85 |
86 | public void setTargetBeanType(Class> targetBeanType) {
87 | this.targetBeanType = targetBeanType;
88 | }
89 |
90 | public List getBeanNames() {
91 | return beanNames;
92 | }
93 |
94 | public void setBeanNames(List beanNames) {
95 | this.beanNames = beanNames;
96 | }
97 |
98 | public String[] getPatterns() {
99 | return patterns;
100 | }
101 |
102 | public void setPatterns(String[] patterns) {
103 | this.patterns = patterns;
104 | }
105 |
106 | public enum AopType {
107 | /**
108 | * aop 类型为name 则beanNames属性不能为空
109 | */
110 | name("name"),
111 | /**
112 | * aop 类型为type 则targetBeanType属性不能为空
113 | */
114 | type("type"),
115 | /**
116 | * aop 类型为advisor 则patterns属性不能为空
117 | */
118 | pointcut("pointcut");
119 |
120 | private String value;
121 |
122 | AopType(String value) {
123 | this.value = value;
124 | }
125 |
126 |
127 | public String getValue() {
128 | return value;
129 | }
130 |
131 | public void setValue(String value) {
132 | this.value = value;
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/java/com/cuisongliu/druid/autoconfigure/stat/DruidTypeAopAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | package com.cuisongliu.druid.autoconfigure.stat;
25 |
26 | import com.alibaba.druid.support.spring.stat.BeanTypeAutoProxyCreator;
27 | import com.cuisongliu.druid.autoconfigure.condition.TypeAopTypesCondition;
28 | import org.springframework.beans.factory.annotation.Value;
29 | import org.springframework.boot.context.properties.ConfigurationProperties;
30 | import org.springframework.context.annotation.Bean;
31 | import org.springframework.context.annotation.Conditional;
32 |
33 | /**
34 | * 按照类型(接口或者父类)来拦截配置stat和spring监控关联
35 | * @author cuisongliu
36 | * @since 2017年5月20日 11:15:26
37 | */
38 | @Conditional(TypeAopTypesCondition.class)
39 | public class DruidTypeAopAutoConfiguration extends DruidStatInitAutoConfiguration{
40 |
41 | @Value("${spring.aop.proxy-target-class:false}")
42 | private boolean proxyTargetClass;
43 |
44 | @Bean
45 | @ConfigurationProperties(DruidStatProperties.DRUID_STAT_PREFIX)
46 | public BeanTypeAutoProxyCreator typeProxyCreator(DruidStatProperties properties){
47 | if (properties.getTargetBeanType() == null){
48 | throw new IllegalStateException(DruidStatProperties.DRUID_STAT_PREFIX+".target-bean-type must not null.");
49 | }
50 | BeanTypeAutoProxyCreator creator = new BeanTypeAutoProxyCreator();
51 | creator.setTargetBeanType(properties.getTargetBeanType());
52 | creator.setProxyTargetClass(proxyTargetClass);
53 | creator.setInterceptorNames(DruidStatProperties.DRUID_STAT_INTERCEPTOR_NAME);
54 | return creator;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/druid-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | # Auto Configure
2 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
3 | com.cuisongliu.druid.autoconfigure.DruidAutoConfiguration
--------------------------------------------------------------------------------
/druid-spring-boot-starter/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | apply from: "$rootDir/gradle/subprojects/druid-spring-boot-starter.gradle"
--------------------------------------------------------------------------------
/druid-spring-boot-starter/src/main/resources/META-INF/spring.provides:
--------------------------------------------------------------------------------
1 | provides: druid-spring-boot-autoconfigure,druid
--------------------------------------------------------------------------------
/gradle/allproject.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | allprojects {
25 | apply from: "$rootDir/gradle/extra/ext.gradle"
26 | group 'com.cuisongliu'
27 | version = "${projectVersion}"
28 | repositories {
29 | mavenLocal()
30 | maven { url "$nexusUrl" }
31 | mavenCentral()
32 | jcenter()
33 | }
34 | }
--------------------------------------------------------------------------------
/gradle/extra/compile.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | tasks.withType(JavaCompile) {
26 | options.encoding = 'UTF-8'
27 | options.compilerArgs << "-Xlint:unchecked"
28 | }
29 |
30 | configurations {
31 | optional
32 | compile.extendsFrom optional
33 | // 所有需要忽略的包定义在此
34 | //all*.exclude group: 'commons-beanutils', module: 'commons-beanutils'
35 | }
36 |
37 | sourceSets {
38 | main {
39 | java {
40 | srcDir 'src/main/java'
41 | }
42 | resources {
43 | srcDir 'src/main/resources'
44 | include '**/*'
45 |
46 | srcDir 'src/main/java'
47 | include '**/*'
48 | exclude '**/*.java'
49 | }
50 | }
51 |
52 | test {
53 | java {
54 | srcDir 'src/test/java'
55 | }
56 | resources {
57 | srcDir 'src/test/resources'
58 | include '**/*'
59 |
60 | srcDir 'src/test/java'
61 | include '**/*'
62 | exclude '**/*.java'
63 | }
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/gradle/extra/ext.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | //定义版本号
26 | ext {
27 | junitVersion = "4.11"
28 | springBootVersion = "1.5.3.RELEASE"
29 | duridVersion = "1.1.5"
30 | projectVersion = "1.3"
31 | projectLocation = "https://github.com/cuisongliu/${rootProject.name}"
32 | baseUrl = "http://maven.cuisongliu.com"
33 | nexusUrl = "$baseUrl/content/groups/public/"
34 | uploadUrl = "$baseUrl/content/repositories/releases/"
35 | uploadSnapshotsUrl = "$baseUrl/content/repositories/snapshots/"
36 | uploadOssUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
37 | uploadOssSnapshotsUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
38 | }
--------------------------------------------------------------------------------
/gradle/extra/pack.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | //打包源代码
26 | task sourcesJar(type: Jar, dependsOn: classes) {
27 | classifier = 'sources'
28 | from sourceSets.main.allSource
29 | }
30 |
31 | javadoc {
32 | options{
33 | encoding "UTF-8"
34 | charSet 'UTF-8'
35 | author true
36 | version true
37 | title "javadoc"
38 | }
39 | }
40 |
41 | task javadocJar(type: Jar, dependsOn: javadoc) {
42 | classifier = 'javadoc'
43 | from javadoc.destinationDir
44 | }
45 |
46 | artifacts {
47 | archives sourcesJar
48 | archives javadocJar
49 | }
50 |
51 | def pomConfig = {
52 | scm {
53 | connection "scm:git:git@github.com:cuisongliu/${rootProject.name}.git"
54 | developerConnection "scm:git:git@github.com:cuisongliu/${rootProject.name}.git"
55 | url "$projectLocation"
56 | }
57 | issueManagement {
58 | system "Github Issue Tracker"
59 | url "$projectLocation/issues"
60 | }
61 | licenses {
62 | license {
63 | name "The MIT License (MIT)"
64 | url "https://opensource.org/licenses/mit-license.php"
65 | distribution "repo"
66 | }
67 | }
68 | developers{
69 | developer{
70 | name "cuisongliu"
71 | email "cuisongliu@qq.com"
72 | }
73 | }
74 | }
75 | signing {
76 | sign configurations.archives
77 | }
78 | nexusStaging {
79 | packageGroup = "com.cuisongliu" //optional if packageGroup == project.getGroup()
80 | stagingProfileId = "64feae5a43b07b" //when not defined will be got from server using "packageGroup"
81 | username = project.hasProperty("ossUsername") ? ossUsername : System.getenv("ossUsername")
82 | password = project.hasProperty("ossPassword") ? ossPassword : System.getenv("ossPassword")
83 | }
84 | uploadArchives {
85 | repositories {
86 | mavenDeployer {
87 | // repository(url: "file:/H://DevSoftWare//MavenResources")
88 | repository(url: "$uploadOssSnapshotsUrl") {
89 | authentication(userName: project.hasProperty("ossUsername") ? ossUsername : System.getenv("ossUsername"),
90 | password: project.hasProperty("ossPassword") ? ossPassword : System.getenv("ossPassword"))
91 | }
92 | repository(url: "$uploadOssUrl") {
93 | authentication(userName: project.hasProperty("ossUsername") ? ossUsername : System.getenv("ossUsername"),
94 | password: project.hasProperty("ossPassword") ? ossPassword : System.getenv("ossPassword"))
95 | }
96 | beforeDeployment { MavenDeployment deployment ->
97 | signing.signPom(deployment)
98 | }
99 | pom.withXml {
100 | def root = asNode()
101 | root.appendNode('url', "$projectLocation")
102 | root.appendNode('description', "druid integration with springboot.")
103 | root.appendNode('name', "$project.name")
104 | root.appendNode('packaging', 'jar')
105 | root.children().last() + pomConfig
106 | }
107 | }
108 | }
109 | }
110 | publishing {
111 | publications {
112 | maven(MavenPublication) {
113 | from components.java
114 |
115 | artifact sourcesJar
116 | artifact javadocJar
117 |
118 | pom.withXml {
119 | def root = asNode()
120 | root.dependencies.dependency.findAll { xmlDep ->
121 | // mark optional dependencies
122 | if (project.configurations.optional.allDependencies.findAll { dep ->
123 | xmlDep.groupId.text() == dep.group && xmlDep.artifactId.text() == dep.name
124 | }) {
125 | def xmlOptional = xmlDep.optional[0];
126 | if (!xmlOptional) {
127 | xmlOptional = xmlDep.appendNode('optional')
128 | }
129 | xmlOptional.value = 'true';
130 | }
131 |
132 | // fix maven-publish issue when all maven dependencies are placed into runtime scope
133 | if (project.configurations.compile.allDependencies.findAll { dep ->
134 | xmlDep.groupId.text() == dep.group && xmlDep.artifactId.text() == dep.name
135 | }) {
136 | def xmlScope = xmlDep.scope[0];
137 | if (!xmlScope) {
138 | xmlScope = xmlDep.appendNode('scope')
139 | }
140 | xmlScope.value = 'compile';
141 | }
142 | }
143 |
144 | root.appendNode('url', "$projectLocation")
145 | root.appendNode('name', "$project.name")
146 | root.children().last() + pomConfig
147 | }
148 |
149 | repositories{
150 | maven {
151 | name 'remoteArtifactory'
152 | url "$uploadUrl"
153 | credentials{
154 | username= project.hasProperty("nexusUsername") ? nexusUsername : System.getenv("nexusUsername")
155 | password= project.hasProperty("nexusPassword") ? nexusPassword : System.getenv("nexusPassword")
156 | }
157 | }
158 | }
159 | repositories{
160 | maven {
161 | name 'remoteSnapshotArtifactory'
162 | url "$uploadSnapshotsUrl"
163 | credentials{
164 | username= project.hasProperty("nexusUsername") ? nexusUsername : System.getenv("nexusUsername")
165 | password= project.hasProperty("nexusPassword") ? nexusPassword : System.getenv("nexusPassword")
166 | }
167 | }
168 | }
169 | }
170 | }
171 | }
--------------------------------------------------------------------------------
/gradle/extra/plugins.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | apply plugin: 'java'
26 | apply plugin: 'maven'
27 | apply plugin: 'idea'
28 | apply plugin: 'signing' //使用signing plugin做数字签名
29 | apply plugin: 'maven-publish'
--------------------------------------------------------------------------------
/gradle/subprojects.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | subprojects {
26 |
27 | apply from: "$rootDir/gradle/extra/plugins.gradle"
28 | apply from: "$rootDir/gradle/extra/compile.gradle"
29 | apply from: "$rootDir/gradle/extra/pack.gradle"
30 |
31 | dependencies {
32 | // 依赖maven中不存在的jar
33 | ext.jarTree = fileTree(dir: 'libs', include: '**/*.jar')
34 | ext.rootProjectLibs = new File(rootProject.rootDir, 'libs').getAbsolutePath()
35 | ext.jarTree += fileTree(dir: rootProjectLibs, include: '**/*.jar')
36 |
37 | compile jarTree
38 | }
39 | // JVM 版本号要求
40 | sourceCompatibility = 1.6
41 | targetCompatibility = 1.6
42 | // java编译的时候缺省状态下会因为中文字符而失败
43 | [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
44 |
45 | }
--------------------------------------------------------------------------------
/gradle/subprojects/druid-spring-boot-autoconfigure.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | def springBootGroup = "org.springframework.boot"
25 |
26 | dependencies {
27 | optional "${springBootGroup}:spring-boot-autoconfigure:${springBootVersion}"
28 | optional "${springBootGroup}:spring-boot-configuration-processor:${springBootVersion}"
29 | optional "${springBootGroup}:spring-boot-starter-web:${springBootVersion}"
30 | optional "com.alibaba:druid:${duridVersion}"
31 | }
--------------------------------------------------------------------------------
/gradle/subprojects/druid-spring-boot-starter.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 cuisongliu@qq.com
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 | def springBootGroup = "org.springframework.boot"
25 |
26 | dependencies {
27 | optional "${springBootGroup}:spring-boot-starter:${springBootVersion}"
28 | compile "${project.group}:druid-spring-boot-autoconfigure:${project.version}"
29 | optional "com.alibaba:druid:${duridVersion}"
30 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'druid-boot-starter'
2 | include 'druid-spring-boot-autoconfigure'
3 | include 'druid-spring-boot-starter'
--------------------------------------------------------------------------------