参考类: com.alibaba.druid.spring.boot.autoconfigure.stat.DruidSpringAopConfiguration
个人怀疑:@ConditionalOnProperty仅能识别到字符串,不能识别yml形式的数组语法
applicaiton.yml == 正确写法
spring:
datasource:
druid:
# 坑,缺少排除选项,且值必须是逗号分割的字符串数组才行,个人建议还是使用自行设置JdkRegexpMethodPointcut拦截切面
aop-patterns: "work.linruchang.*,work.linruchang.config.*"
applicaiton.yml == 错误写法
spring:
datasource:
druid:
# 坑,无排除选项,且值必须是逗号分割的字符串数组,虽然通过@Value能获取到数组,但是不能被@ConditionalOnProperty注解识别到
aop-patterns:
- "work.linruchang.*"
- "work.linruchang.config.*"
@Configuration
public class SpringConfig implements WebMvcConfigurer {
@Bean
public DruidStatInterceptor druidStatInterceptor() {
DruidStatInterceptor dsInterceptor = new DruidStatInterceptor();
return dsInterceptor;
}
@Bean
public JdkRegexpMethodPointcut druidStatPointcut() {
JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
pointcut.setPattern("work.linruchang.*");//根据实际包名
pointcut.setExcludedPatterns("work.linruchang.kafkaUiLite.conf.*", ".*config.*");
return pointcut;
}
@Bean
public DefaultPointcutAdvisor druidStatAdvisor(DruidStatInterceptor druidStatInterceptor, JdkRegexpMethodPointcut druidStatPointcut) {
DefaultPointcutAdvisor defaultPointAdvisor = new DefaultPointcutAdvisor();
defaultPointAdvisor.setPointcut(druidStatPointcut);
defaultPointAdvisor.setAdvice(druidStatInterceptor);
return defaultPointAdvisor;
}
}