提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.datasource.config; |
H |
2 |
|
|
3 |
import com.iailab.framework.datasource.core.filter.DruidAdRemoveFilter; |
|
4 |
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; |
|
5 |
import org.springframework.boot.autoconfigure.AutoConfiguration; |
|
6 |
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
|
7 |
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|
8 |
import org.springframework.boot.web.servlet.FilterRegistrationBean; |
|
9 |
import org.springframework.context.annotation.Bean; |
|
10 |
import org.springframework.transaction.annotation.EnableTransactionManagement; |
|
11 |
|
|
12 |
/** |
|
13 |
* 数据库配置类 |
|
14 |
* |
|
15 |
* @author iailab |
|
16 |
*/ |
|
17 |
@AutoConfiguration |
|
18 |
@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理 |
|
19 |
@EnableConfigurationProperties(DruidStatProperties.class) |
|
20 |
public class IailabDataSourceAutoConfiguration { |
|
21 |
|
|
22 |
/** |
|
23 |
* 创建 DruidAdRemoveFilter 过滤器,过滤 common.js 的广告 |
|
24 |
*/ |
|
25 |
@Bean |
|
26 |
@ConditionalOnProperty(name = "spring.datasource.druid.stat-view-servlet.enabled", havingValue = "true") |
|
27 |
public FilterRegistrationBean<DruidAdRemoveFilter> druidAdRemoveFilterFilter(DruidStatProperties properties) { |
|
28 |
// 获取 druid web 监控页面的参数 |
|
29 |
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet(); |
|
30 |
// 提取 common.js 的配置路径 |
|
31 |
String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*"; |
|
32 |
String commonJsPattern = pattern.replaceAll("\\*", "js/common.js"); |
|
33 |
// 创建 DruidAdRemoveFilter Bean |
|
34 |
FilterRegistrationBean<DruidAdRemoveFilter> registrationBean = new FilterRegistrationBean<>(); |
|
35 |
registrationBean.setFilter(new DruidAdRemoveFilter()); |
|
36 |
registrationBean.addUrlPatterns(commonJsPattern); |
|
37 |
return registrationBean; |
|
38 |
} |
|
39 |
|
|
40 |
} |