
com.github.anonymousmister.bootfastconfig.config.WebMvcHandlerMethodConf Maven / Gradle / Ivy
package com.github.anonymousmister.bootfastconfig.config;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import java.util.LinkedList;
import java.util.List;
import static com.github.anonymousmister.bootfastconfig.constant.BeanNameConstant.JSON_PARAM_ARGUMENT_RESOLVER;
/**
* @author admin
* @title: WebMvc
* @projectName demo
* @description: 初始化 参数解析配置
* @date 2019/7/115:57
*/
@Component
public class WebMvcHandlerMethodConf implements ApplicationContextAware {
@Qualifier(JSON_PARAM_ARGUMENT_RESOLVER)
@Autowired
private HandlerMethodArgumentResolver jsonParamArgumentResolver;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
LinkedList handlerResolvers = new LinkedList<>();
RequestMappingHandlerAdapter bean = applicationContext.getBean(RequestMappingHandlerAdapter.class);
List argumentResolvers = bean.getArgumentResolvers();
argumentResolvers.stream().forEach(handlerResolvers::add);
handlerResolvers.addFirst(jsonParamArgumentResolver);
bean.setArgumentResolvers(handlerResolvers);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy