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

com.feingto.cloud.config.feign.BasicAuthConfiguration Maven / Gradle / Ivy

There is a newer version: 2.3.8.RELEASE
Show newest version
package com.feingto.cloud.config.feign;

import com.feingto.cloud.config.annotation.ExcludeComponentScan;
import feign.Contract;
import feign.Logger;
import feign.auth.BasicAuthRequestInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Feign BasicAuth 配置
 *
 * @author longfei
 */
@Slf4j
@Configuration
@ConditionalOnBean(annotation = FeignClient.class)
@ExcludeComponentScan
public class BasicAuthConfiguration {
    @Value("${spring.security.user:user}")
    private String username;

    @Value("${spring.security.user.password:123456}")
    private String password;

    @Bean
    public Contract feignContract() {
        return new feign.Contract.Default();
    }

    @Bean
    public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new BasicAuthRequestInterceptor(username, password);
    }

    @Bean
    public Logger.Level feignLoggerLevel() {
        return Logger.Level.BASIC;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy