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

org.zodiac.autoconfigure.eureka.EurekaBaseAutoConfiguration Maven / Gradle / Ivy

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

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.zodiac.autoconfigure.application.ApplicationInfoProperties;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnAppDiscoveryEnabled;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnSpringCloudBootstrapDisabled;
import org.zodiac.autoconfigure.bootstrap.discovery.AppDiscoveryProperties;
import org.zodiac.autoconfigure.eureka.condition.ConditionalOnEurekaEnabled;
import org.zodiac.commons.constants.Constants;
import org.zodiac.commons.util.lang.Numbers;
import org.zodiac.commons.util.spring.Springs;

@SpringBootConfiguration
@ConditionalOnEurekaEnabled
@ConditionalOnAppDiscoveryEnabled
@ConditionalOnSpringCloudBootstrapDisabled
@ConditionalOnClass(value = {org.zodiac.eureka.client.EurekaAppDiscoveryClient.class, com.netflix.discovery.EurekaClient.class, com.netflix.config.ConfigurationManager.class})
public class EurekaBaseAutoConfiguration {

    private ApplicationInfoProperties applicationInfoProperties;
    private AppDiscoveryProperties appDiscoveryProperties;
    private ServerProperties serverProperties;

    public EurekaBaseAutoConfiguration(ApplicationInfoProperties applicationInfoProperties, AppDiscoveryProperties appDiscoveryProperties,
        ServerProperties serverProperties) {
        this.applicationInfoProperties = applicationInfoProperties;
        this.appDiscoveryProperties = appDiscoveryProperties;
        this.serverProperties = serverProperties;
    }

    @Bean
    @ConfigurationProperties(prefix = org.zodiac.eureka.base.constants.EurekaBaseSystemPropertiesConstants.EUREKA_LOCAL_PREFIX)
    protected EurekaLocalProperties eurekaLocalProperties() {
        Integer port = Numbers.getOrDefault(serverProperties.getPort(), Constants.Spring.DEFAULT_SERVER_PORT_NUMBER);
        Integer securePort = serverProperties.getSsl() != null && serverProperties.getSsl().isEnabled() ? port : -1;
        String urlPrefix = Springs.isServletWeb() ? serverProperties.getServlet().getContextPath() : "";
        if (null == urlPrefix)
            urlPrefix = "";
        return new EurekaLocalProperties(port, securePort, urlPrefix);
    }

    @Bean
    @ConfigurationProperties(prefix = org.zodiac.eureka.base.constants.EurekaBaseSystemPropertiesConstants.EUREKA_PREFIX)
    protected EurekaProperties eurekaProperties(EurekaLocalProperties eurekaLocalProperties) {
        EurekaProperties eurekaProperties =
            new EurekaProperties(applicationInfoProperties, appDiscoveryProperties, eurekaLocalProperties);
        return eurekaProperties;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy