Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
shop
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
shop
Commits
55b81ab3
Commit
55b81ab3
authored
Aug 31, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加Druid数据源监控
parent
f57d2e18
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
438 additions
and
6 deletions
+438
-6
pom.xml
pom.xml
+5
-6
WebStatFilter.java
...in/java/com/alibaba/druid/support/http/WebStatFilter.java
+359
-0
DruidConfig.java
src/main/java/com/egolm/shop/config/DruidConfig.java
+71
-0
application-dev.properties
src/main/resources/application-dev.properties
+1
-0
application-pro.properties
src/main/resources/application-pro.properties
+1
-0
application-test.properties
src/main/resources/application-test.properties
+1
-0
No files found.
pom.xml
View file @
55b81ab3
...
...
@@ -39,12 +39,16 @@
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
1.1.20
</version>
</dependency>
<dependency>
<groupId>
com.microsoft.sqlserver
</groupId>
<artifactId>
sqljdbc4
</artifactId>
<version>
4.0
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
...
...
@@ -55,11 +59,6 @@
<artifactId>
common
</artifactId>
<version>
0.0.1-RELEASE
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
<version>
1.1.6
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
...
...
src/main/java/com/alibaba/druid/support/http/WebStatFilter.java
0 → 100644
View file @
55b81ab3
This diff is collapsed.
Click to expand it.
src/main/java/com/egolm/shop/config/DruidConfig.java
0 → 100644
View file @
55b81ab3
package
com
.
egolm
.
shop
.
config
;
import
java.io.IOException
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
;
import
com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties
;
import
com.alibaba.druid.support.http.StatViewServlet
;
import
com.alibaba.druid.support.http.WebStatFilter
;
import
com.alibaba.druid.util.Utils
;
@Configuration
@ConditionalOnWebApplication
@AutoConfigureAfter
(
DruidDataSourceAutoConfigure
.
class
)
@ConditionalOnProperty
(
name
=
"spring.datasource.druid.stat-view-servlet.enabled"
,
havingValue
=
"true"
,
matchIfMissing
=
true
)
public
class
DruidConfig
{
@Bean
public
FilterRegistrationBean
<
Filter
>
bannerFilterRegistrationBean
(
DruidStatProperties
properties
)
{
DruidStatProperties
.
StatViewServlet
config
=
properties
.
getStatViewServlet
();
String
pattern
=
config
.
getUrlPattern
()
!=
null
?
config
.
getUrlPattern
()
:
"/druid/*"
;
String
commonJsPattern
=
pattern
.
replaceAll
(
"\\*"
,
"js/common.js"
);
final
String
filePath
=
"support/http/resources/js/common.js"
;
Filter
filter
=
new
Filter
()
{
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
chain
.
doFilter
(
request
,
response
);
response
.
resetBuffer
();
String
text
=
Utils
.
readFromResource
(
filePath
);
text
=
text
.
replaceAll
(
"<a.*?banner\"></a><br/>"
,
""
);
text
=
text
.
replaceAll
(
"powered.*?shrek.wang</a>"
,
""
);
response
.
getWriter
().
write
(
text
);
}
};
FilterRegistrationBean
<
Filter
>
registrationBean
=
new
FilterRegistrationBean
<
Filter
>();
registrationBean
.
setFilter
(
filter
);
registrationBean
.
addUrlPatterns
(
commonJsPattern
);
return
registrationBean
;
}
@Bean
public
FilterRegistrationBean
<
Filter
>
webStatFilterRegistrationBean
(
DruidStatProperties
properties
)
{
WebStatFilter
filter
=
new
WebStatFilter
();
FilterRegistrationBean
<
Filter
>
registrationBean
=
new
FilterRegistrationBean
<
Filter
>();
registrationBean
.
setFilter
(
filter
);
registrationBean
.
addUrlPatterns
(
"/*"
);
registrationBean
.
addInitParameter
(
"exclusions"
,
"*.js, *.gif, *.jpg, *.bmp, *.png, *.css, *.ico, /druid/*"
);
return
registrationBean
;
}
@Bean
public
ServletRegistrationBean
<?>
setvletRegistrationBean
()
{
ServletRegistrationBean
<
StatViewServlet
>
setvletRegistrationBean
=
new
ServletRegistrationBean
<
StatViewServlet
>(
new
StatViewServlet
(),
"/druid/*"
);
setvletRegistrationBean
.
addInitParameter
(
"resetEnable"
,
"true"
);
return
setvletRegistrationBean
;
}
}
src/main/resources/application-dev.properties
View file @
55b81ab3
...
...
@@ -20,6 +20,7 @@ spring.datasource.testWhileIdle=true
spring.datasource.validationQueryTimeout
=
5
spring.datasource.validationQuery
=
SELECT 1
spring.datasource.timeBetweenEvictionRunsMillis
=
3600000
spring.datasource.filters
=
stat,wall,log4j
spring.redis.database
=
0
...
...
src/main/resources/application-pro.properties
View file @
55b81ab3
...
...
@@ -20,6 +20,7 @@ spring.datasource.testWhileIdle=true
spring.datasource.validationQueryTimeout
=
5
spring.datasource.validationQuery
=
SELECT 1
spring.datasource.timeBetweenEvictionRunsMillis
=
3600000
spring.datasource.filters
=
stat,wall,log4j
spring.redis.database
=
0
...
...
src/main/resources/application-test.properties
View file @
55b81ab3
...
...
@@ -20,6 +20,7 @@ spring.datasource.testWhileIdle=true
spring.datasource.validationQueryTimeout
=
5
spring.datasource.validationQuery
=
SELECT 1
spring.datasource.timeBetweenEvictionRunsMillis
=
3600000
spring.datasource.filters
=
stat,wall,log4j
spring.redis.database
=
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment