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

io.github.admin4j.http.config.HttpAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 0.9.2
Show newest version
package io.github.admin4j.http.config;

import io.github.admin4j.http.ApiClient;
import io.github.admin4j.http.ApiJsonClient;
import io.github.admin4j.http.HttpPropsConfiguration;
import io.github.admin4j.http.core.HttpDefaultConfig;
import io.github.admin4j.http.util.HttpJsonUtil;
import io.github.admin4j.http.util.HttpUtil;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

import javax.annotation.PostConstruct;

/**
 * @author andanyang
 * @since 2022/11/3 15:27
 */
@EnableConfigurationProperties(HttpPropsConfiguration.class)
@ConditionalOnProperty(prefix = "admin4j.http", name = "enabled", matchIfMissing = true)
public class HttpAutoConfiguration implements InitializingBean {
    @Autowired
    HttpPropsConfiguration httpConfig;

    @PostConstruct
    public void initHttpClient() {

        HttpDefaultConfig.set(httpConfig);
        ApiClient apiClient = new ApiClient(httpConfig);
        HttpUtil.setClient(apiClient);
        ApiJsonClient apiJsonClient = new ApiJsonClient(httpConfig);
        HttpJsonUtil.setClient(apiJsonClient);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        HttpDefaultConfig.set(httpConfig);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy