org.zodiac.autoconfigure.application.DefaultServletApplicatuonBootstrapAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.application;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.zodiac.core.logging.trace.ServletTraceLoggingMDCFilter;
@SpringBootConfiguration
@ConditionalOnWebApplication(type = Type.SERVLET)
@AutoConfigureAfter(value = {DefaultApplicatuonBootstrapAutoConfiguration.class})
public class DefaultServletApplicatuonBootstrapAutoConfiguration {
private final ApplicationContext applicationContext;
public DefaultServletApplicatuonBootstrapAutoConfiguration(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Bean
@ConditionalOnMissingBean(value = {ServletTraceLoggingMDCFilter.class})
protected ServletTraceLoggingMDCFilter defaultTraceLoggingMDCFilter() {
return new ServletTraceLoggingMDCFilter(applicationContext) {};
}
@Bean
//@ConditionalOnBean(value = {ServletTraceLoggingMDCFilter.class})
protected FilterRegistrationBean defaultTraceLoggingMDCFilterBean(ServletTraceLoggingMDCFilter filter) {
FilterRegistrationBean filterBean = new FilterRegistrationBean<>(filter);
filterBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
/*Cannot use '/*' or it will not be added to the container chain (only '/**')*/
filterBean.addUrlPatterns("/*");
return filterBean;
}
}