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

org.zodiac.autoconfigure.bootstrap.breaker.dip.AppBreakerDipAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.bootstrap.breaker.dip;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnBreakerDipEnabled;
import org.zodiac.core.application.AppInstanceOps;
import org.zodiac.core.bootstrap.breaker.dip.reactive.AppDipWebFilter;
import org.zodiac.core.bootstrap.breaker.dip.reactive.ReactiveAppDipService;
import org.zodiac.core.bootstrap.breaker.dip.servlet.AppDipHandlerInterceptor;
import org.zodiac.core.bootstrap.breaker.dip.servlet.ServletAppDipService;
import org.zodiac.core.context.config.annotation.AppRefreshScope;

import javax.annotation.Resource;

@SpringBootConfiguration
@ConditionalOnBreakerDipEnabled
@EnableConfigurationProperties(value = {AppRoutingDipProperties.class})
public class AppBreakerDipAutoConfiguration {

    @SpringBootConfiguration
    @ConditionalOnBreakerDipEnabled
    @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
    protected static class ServletDipConfiguration implements WebMvcConfigurer, Ordered {

        @Resource
        private AppDipHandlerInterceptor appDipHandlerInterceptor;

        @Bean
        @AppRefreshScope
        protected ServletAppDipService servletAppDipService(AppRoutingDipProperties appRoutingDipProperties) {
            return new ServletAppDipService(appRoutingDipProperties);
        }

        @Bean
        protected AppDipHandlerInterceptor dipHandlerInterceptor(ServletAppDipService appDipService,
            AppInstanceOps appInstanceOps) {
            return new AppDipHandlerInterceptor(appDipService, appInstanceOps);
        }

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(appDipHandlerInterceptor);
        }

        @Override
        public int getOrder() {
            return Ordered.LOWEST_PRECEDENCE;
        }
    }

    @SpringBootConfiguration
    @ConditionalOnBreakerDipEnabled
    @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
    protected static class ReactiveDipConfiguration {

        @Bean
        @AppRefreshScope
        protected ReactiveAppDipService reactiveAppDipService(AppRoutingDipProperties appRoutingDipProperties) {
            return new ReactiveAppDipService(appRoutingDipProperties);
        }

        @Bean
        protected AppDipWebFilter appDipWebFilter(ReactiveAppDipService appDipService, AppInstanceOps appInstanceOps) {
            return new AppDipWebFilter(appDipService, appInstanceOps);
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy