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

org.zodiac.autoconfigure.sentinel.SentinelInfraAutoConfiguration Maven / Gradle / Ivy

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

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnSpringCloudBootstrapDisabled;
import org.zodiac.autoconfigure.sentinel.condition.ConditionalOnSentinelConfigEnabled;
import org.zodiac.commons.constants.SystemPropertiesConstants;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

@SpringBootConfiguration
@ConditionalOnSentinelConfigEnabled
@ConditionalOnSpringCloudBootstrapDisabled
@ConditionalOnClass(value = {com.alibaba.csp.sentinel.Env.class, com.alibaba.csp.sentinel.annotation.aspectj.AbstractSentinelAspectSupport.class, org.zodiac.sentinel.base.model.SentinelRule.class})
public class SentinelInfraAutoConfiguration {

    private String projectName;

    public SentinelInfraAutoConfiguration(
        @Value("${" + org.zodiac.sentinel.base.constants.SentinelBaseSystemPropertiesConstants.Sentinel.PROJECT_NAME + ":${" + SystemPropertiesConstants.Spring.SPRING_APP_NAME + ":}}") String projectName) {
        this.projectName = projectName;
    }

    @Bean
    @ConditionalOnMissingBean
    @ConfigurationProperties(prefix = org.zodiac.sentinel.base.constants.SentinelBaseSystemPropertiesConstants.Zodiac.SENTINEL_PREFIX)
    protected SentinelConfigProperties sentinelConfigProperties() {
        return new SentinelConfigProperties();
    }

    @Bean
    @ConditionalOnMissingBean
    protected org.zodiac.sentinel.base.config.configurer.SentinelConfigurer sentinelConfigurer(SentinelConfigProperties sentinelConfigProperties) {
        return new org.zodiac.sentinel.base.config.configurer.SentinelConfigurer(projectName, sentinelConfigProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass(value = {com.fasterxml.jackson.databind.JavaType.class})
    protected org.zodiac.sentinel.base.config.configurer.SentinelJsonConfigurer sentinelJsonConfigurer(ObjectProvider mapperProvider) {
        return new org.zodiac.sentinel.base.config.configurer.SentinelJsonConfigurer(mapperProvider.getIfAvailable());
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass(value = {com.fasterxml.jackson.dataformat.xml.PackageVersion.class})
    protected org.zodiac.sentinel.base.config.configurer.SentinelXmlConfigurer sentinelXmlConfigurer(ObjectProvider mapperProvider) {
        return new org.zodiac.sentinel.base.config.configurer.SentinelXmlConfigurer(mapperProvider.getIfAvailable());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy