All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.guanmengyuan.spring.ex.web.config.SpringWebAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 3.3.3.2
Show newest version
package com.guanmengyuan.spring.ex.web.config;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.annotation.Order;
import org.springframework.format.FormatterRegistry;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.guanmengyuan.spring.ex.common.model.converter.AnyToEnumConverterFactory;

@Configuration
@EnableConfigurationProperties(SpringWebProperties.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@Order(-100)
@Primary
public class SpringWebAutoConfiguration implements WebMvcConfigurer {
    private final ServerProperties serverProperties;

    @Override
    public void addFormatters(@NonNull FormatterRegistry registry) {
        registry.addConverterFactory(new AnyToEnumConverterFactory());
    }

    public SpringWebAutoConfiguration(ServerProperties serverProperties) {
        this.serverProperties = serverProperties;
    }

    @Primary
    @Bean
    public BasicErrorController basicErrorController(ErrorAttributes errorAttributes,
            ObjectProvider errorViewResolvers) {
        return new GlobalErrorController(serverProperties);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy