org.zodiac.autoconfigure.bootstrap.breaker.dip.AppBreakerDipAutoConfiguration Maven / Gradle / Ivy
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);
}
}
}