com.zrun.commons.web.ZRunWebMvcConfigurer Maven / Gradle / Ivy
The newest version!
package com.zrun.commons.web;
import com.zrun.commons.core.listener.OperLogListener;
import com.zrun.commons.core.service.RemoteServiceHolder;
import com.zrun.commons.web.converter.String2EnumConvertFactory;
import com.zrun.commons.web.filter.BodyRepeatReaderFilter;
import com.zrun.commons.web.handler.GlobalExceptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
public class ZRunWebMvcConfigurer implements WebMvcConfigurer {
@Autowired
private String2EnumConvertFactory string2EnumConvertFactory;
/**
* 操作日志记录到数据库
*/
@ConditionalOnProperty(prefix = "operLog.db", name = "enabled", havingValue = "true", matchIfMissing = false)
@Bean("operLogListenerDB")
public OperLogListener operLogListener() {
return new OperLogListener((operLogDTO -> {
RemoteServiceHolder.getLogService().saveLog(operLogDTO);
}));
}
@Bean
public GlobalExceptionHandler globalExceptionHandler(){
return new GlobalExceptionHandler();
}
@Bean
public BodyRepeatReaderFilter bodyRepeatReaderFilter(){
return new BodyRepeatReaderFilter();
}
@Override
public void addFormatters(FormatterRegistry registry) {
// 字符串转枚举,请求参数反序列化
registry.addConverterFactory(string2EnumConvertFactory);
}
}