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

org.zodiac.autoconfigure.web.ReactiveWebAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.commons.excel.ExcelOperations;
import org.zodiac.commons.excel.ReactiveExcelTemplate;
import org.zodiac.core.web.modle.WebLocaleResolver;
import org.zodiac.core.web.reactive.filter.OrderedFormContentFilter;

@SpringBootConfiguration
@ConditionalOnWebApplication(type = Type.REACTIVE)
@ConditionalOnClass(value = {org.springframework.web.server.WebHandler.class, org.springframework.web.reactive.DispatcherHandler.class})
public class ReactiveWebAutoConfiguration {

    private RequestMappingHandlerAdapter requestMappingHandlerAdapter;
    private RequestMappingHandlerMapping requestMappingHandlerMapping;

    public ReactiveWebAutoConfiguration(
        @Qualifier(value = "requestMappingHandlerAdapter") @Autowired(required = false) RequestMappingHandlerAdapter requestMappingHandlerAdapterProvider,
        @Qualifier(value = "requestMappingHandlerMapping") @Autowired(required = false) RequestMappingHandlerMapping requestMappingHandlerMapping) {
        this.requestMappingHandlerAdapter = requestMappingHandlerAdapterProvider;
        this.requestMappingHandlerMapping = requestMappingHandlerMapping;
    }

    @Bean
    @ConditionalOnMissingBean
    @ConfigurationProperties(prefix = org.zodiac.commons.constants.SystemPropertiesConstants.Zodiac.SPRING_WEBFLUX_PREFIX)
    protected WebFluxConfigProperties webFluxConfigProperties() {
        return new WebFluxConfigProperties();
    }

    @Bean
    @ConditionalOnMissingBean
    protected org.zodiac.commons.web.ReactiveRequestContextHolderFilter reactiveRequestContextHolderFilter() {
        return new org.zodiac.commons.web.ReactiveRequestContextHolderFilter();
    }

    @Bean
    @ConditionalOnMissingBean(value = org.zodiac.core.web.reactive.filter.FormContentFilter.class)
    @ConditionalOnProperty(name = SystemPropertiesConstants.Zodiac.SPRING_WEBFLUX_FORMCONTENT_FILTER_ENABLED, matchIfMissing = true)
    public OrderedFormContentFilter formContentFilter() {
        return new OrderedFormContentFilter();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(name = SystemPropertiesConstants.Zodiac.SPRING_WEBFLUX_LOCALE)
    public org.springframework.web.server.i18n.LocaleContextResolver localeContextResolver(WebFluxConfigProperties webFluxConfigProperties) {
        if (webFluxConfigProperties.getLocaleResolver() == WebLocaleResolver.FIXED) {
            return new org.springframework.web.server.i18n.FixedLocaleContextResolver(webFluxConfigProperties.getLocale(),
                webFluxConfigProperties.getTimeZone());
        }
        org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver localeContextResolver = new org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver();
        localeContextResolver.setDefaultLocale(webFluxConfigProperties.getLocale());
        localeContextResolver.setSupportedLocales(webFluxConfigProperties.getSupportedLocales());
        return localeContextResolver;
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass
    protected org.zodiac.core.web.WebOperations webOperations() {
        return new org.zodiac.core.web.reactive.ReactiveWebTemplate();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass(name = {"com.alibaba.excel.write.handler.WriteHandler"})
    protected ExcelOperations excelOperations() {
        return new ReactiveExcelTemplate();
    }

    @Bean
    @ConditionalOnMissingBean
    protected org.zodiac.core.web.reactive.MyReactiveDemoController myReactiveDemoController() {
        return new org.zodiac.core.web.reactive.MyReactiveDemoController();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy