@Bean @ConditionalOnBean(ManagementServerProperties.class) public SkipPatternProvider skipPatternForManagementServerProperties( final ManagementServerProperties managementServerProperties) { return new SkipPatternProvider() { @Override public Pattern skipPattern() { return getPatternForManagementServerProperties( managementServerProperties, SkipPatternProviderConfig.this.skipPattern); } }; }
/** * Sets or appends {@link ManagementServerProperties#getContextPath()} to the * skip pattern. If neither is available then sets the default one */ static Pattern getPatternForManagementServerProperties( ManagementServerProperties managementServerProperties, String skipPattern) { if (StringUtils.hasText(skipPattern) && StringUtils.hasText(managementServerProperties.getContextPath())) { return Pattern.compile(skipPattern + "|" + managementServerProperties.getContextPath() + ".*"); } else if (StringUtils.hasText(managementServerProperties.getContextPath())) { return Pattern.compile(managementServerProperties.getContextPath() + ".*"); } return defaultSkipPattern(skipPattern); }
@Test public void should_pick_skip_pattern_when_its_not_empty_and_management_context_is_empty() throws Exception { String skipPattern = "foo.*|bar.*"; Pattern pattern = SkipPatternProviderConfig.getPatternForManagementServerProperties(new ManagementServerProperties(), skipPattern); then(pattern.pattern()).isEqualTo("foo.*|bar.*"); }
@Test public void should_pick_default_pattern_when_both_management_context_and_skip_patterns_are_empty() throws Exception { String skipPattern = ""; Pattern pattern = SkipPatternProviderConfig.getPatternForManagementServerProperties(new ManagementServerProperties(), skipPattern); then(pattern.pattern()).isEqualTo(TraceFilter.DEFAULT_SKIP_PATTERN); }
/*** * 修改actuator的默认contextPath */ @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if(bean instanceof ManagementServerProperties){ /*ManagementServerProperties props = (ManagementServerProperties) bean; if(StringUtils.isBlank(props.getContextPath())){ props.setContextPath(BootWebUtils.CONTROLLER_PREFIX+"/management"); }*/ /*if(props.getAddress()==null){ props.setAddress(NetUtils.getInetAddress("127.0.0.1", null)); }*/ } return bean; }
@Bean @ConditionalOnMissingBean(ManagementServerProperties.class) public SkipPatternProvider defaultSkipPatternBeanIfManagementServerPropsArePresent() { return defaultSkipPatternProvider(this.skipPattern); }
private ManagementServerProperties managementServerPropertiesWithContextPath() { ManagementServerProperties managementServerProperties = new ManagementServerProperties(); managementServerProperties.setContextPath("/management/context"); return managementServerProperties; }