com.yahacode.hiddenblade.app.mock.MockConfiguration Maven / Gradle / Ivy
The newest version!
package com.yahacode.hiddenblade.app.mock;
import feign.Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnProperty(prefix = "hb.mock", value = "switch", havingValue = "true")
@EnableConfigurationProperties(MockProperties.class)
public class MockConfiguration {
private static final Logger log = LoggerFactory.getLogger(MockConfiguration.class);
@Autowired
MockProperties properties;
@Autowired
CachingSpringLoadBalancerFactory cachingFactory;
@Autowired
SpringClientFactory clientFactory;
@Bean
public Client feignClient() {
log.info("init mock feign client");
return new LoadBalancerFeignClient(new MockFeignClient(new Client.Default(null, null), properties.getFeign()),
cachingFactory, clientFactory);
}
}