liujie
2026-01-14 f976a39b294f8c7dd60bcd2c661983c0dcc97fc6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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<AbstractExceptionHandler.ExceptionContext> getExceptionConsumer() {
                    return context -> log.error("未捕获内部异常, logText: {}", context.dumpRequest(), context.getException());
                }
            };
        }
    }
}