org.zodiac.autoconfigure.log.PlatformLogErrorServletAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.log;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
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.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.context.annotation.Bean;
import org.zodiac.autoconfigure.log.condition.ConditionalOnPatformLogRequestEnabled;
import org.zodiac.autoconfigure.log.error.ServletErrorController;
@SpringBootConfiguration
@ConditionalOnPatformLogRequestEnabled
@ConditionalOnWebApplication(type = Type.SERVLET)
@AutoConfigureBefore(value = {ErrorMvcAutoConfiguration.class})
@ConditionalOnClass(value = {org.zodiac.log.LogOperations.class, javax.servlet.Servlet.class, org.springframework.web.servlet.DispatcherServlet.class})
public class PlatformLogErrorServletAutoConfiguration {
private final ServerProperties serverProperties;
private final org.zodiac.log.publisher.ErrorLogPublisher errorLogPublisher;
public PlatformLogErrorServletAutoConfiguration(ServerProperties serverProperties,
ObjectProvider errorLogPublisherProvider) {
this.serverProperties = serverProperties;
this.errorLogPublisher = errorLogPublisherProvider.getIfAvailable();
}
@Bean
@ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT)
protected DefaultErrorAttributes errorAttributes() {
return new org.zodiac.log.error.ServletErrorAttributes(errorLogPublisher);
}
@Bean
@ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT)
protected BasicErrorController basicErrorController(ErrorAttributes errorAttributes) {
return new ServletErrorController(errorAttributes, serverProperties.getError());
}
}