|
| 1 | +package com.github.lybgeek.chaincontext.autoconfig; |
| 2 | + |
| 3 | +import com.github.lybgeek.chaincontext.ChainContextProperties; |
| 4 | +import com.github.lybgeek.chaincontext.feign.FeignConfiguration; |
| 5 | +import com.github.lybgeek.chaincontext.hystrix.HystrixChainContextConfiguration; |
| 6 | +import com.github.lybgeek.chaincontext.mvc.ChainContextWebMvcConfigure; |
| 7 | +import com.github.lybgeek.chaincontext.mvc.ChainContexthandlerInterceptor; |
| 8 | +import com.github.lybgeek.chaincontext.parser.DefaultRequestKeyParser; |
| 9 | +import com.github.lybgeek.chaincontext.parser.IRequestKeyParser; |
| 10 | +import com.github.lybgeek.chaincontext.rest.ChainContextBeanPostProcessor; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; |
| 12 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
| 13 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 14 | +import org.springframework.context.annotation.Bean; |
| 15 | +import org.springframework.context.annotation.Configuration; |
| 16 | +import org.springframework.context.annotation.Import; |
| 17 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +/** |
| 22 | + * |
| 23 | + * @author linyb |
| 24 | + * |
| 25 | + */ |
| 26 | +@Configuration |
| 27 | +@Import({FeignConfiguration.class, HystrixChainContextConfiguration.class}) |
| 28 | +@EnableConfigurationProperties(ChainContextProperties.class) |
| 29 | +public class ChainContextAutoConfiguration implements WebMvcConfigurer { |
| 30 | + |
| 31 | + @Autowired |
| 32 | + private ChainContextProperties chainContextProperties; |
| 33 | + |
| 34 | + @ConditionalOnMissingBean |
| 35 | + @Bean |
| 36 | + public IRequestKeyParser requestKeyParser() { |
| 37 | + return new DefaultRequestKeyParser(); |
| 38 | + } |
| 39 | + |
| 40 | + @Bean |
| 41 | + public WebMvcConfigurer webMvcConfigurer(IRequestKeyParser requestKeyParser) { |
| 42 | + ChainContexthandlerInterceptor interceptor = new ChainContexthandlerInterceptor(chainContextProperties, requestKeyParser); |
| 43 | + return new ChainContextWebMvcConfigure(interceptor); |
| 44 | + } |
| 45 | + |
| 46 | + @Bean |
| 47 | + public ChainContextBeanPostProcessor chainContextBeanPostProcessor() { |
| 48 | + return new ChainContextBeanPostProcessor(); |
| 49 | + } |
| 50 | + |
| 51 | +} |
0 commit comments