package com.estate.expert.admin.config; import com.estate.expert.common.AppRuntime; import com.estate.expert.common.config.DefaultWebMvcConfig; import com.estate.expert.common.exception.AbstractExceptionHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Profile; import java.util.function.Consumer; /** * Server服务唯一的配置入口 GlobalConfig.class, DefaultWebMvcConfig.class, * @author code */ @Slf4j @Configuration @Import({GlobalConfig.class, DefaultWebMvcConfig.class, CorsConfig.class}) public class Config { /** * XXX: ExceptionHandlerConfig 应该在 DefaultWebMvcConfig 前被初始. 否则 DefaultWebMvcConfig 的 exceptionHandlerHook 会生效 */ static class ExceptionHandlerConfig { @Bean @Profile({"!unittest && !local"}) AbstractExceptionHandler.ExceptionHandlerHook exceptionHandlerHook(AppRuntime appRuntime) { return new AbstractExceptionHandler.ExceptionHandlerHook() { @Override public String getAppId() { return appRuntime.getAppId(); } @Override public Consumer getExceptionConsumer() { return context -> log.error("未捕获内部异常, logText: {}", context.dumpRequest(), context.getException()); } }; } } }