GatewayApp.java
2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.viontech.fanxing.forward;
import feign.codec.Decoder;
import feign.optionals.OptionalDecoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.support.ResponseEntityDecoder;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.util.ArrayList;
import java.util.List;
/**
* .
*
* @author 谢明辉
* @date 2021/6/11
*/
@SpringBootApplication
@ComponentScan(basePackages = "com.viontech.fanxing", excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = com.viontech.fanxing.commons.config.WebConfig.class),
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = com.viontech.fanxing.commons.base.GlobalExceptionHandler.class)
})
@EnableDiscoveryClient
@EnableScheduling
@EnableFeignClients(basePackages = "com.viontech.fanxing")
@Slf4j
public class GatewayApp {
public static void main(String[] args) {
try {
SpringApplication.run(GatewayApp.class, args);
} catch (Exception e) {
log.error("gateway app start error", e);
}
}
@Bean
public Decoder feignDecoder(MyMappingJackson2HttpMessageConverter converter) {
ObjectFactory<HttpMessageConverters> factory = () -> new HttpMessageConverters(converter);
return new OptionalDecoder(
new ResponseEntityDecoder(new SpringDecoder(factory)));
}
@Bean
public MyMappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
return new MyMappingJackson2HttpMessageConverter();
}
@Bean
public HttpMessageConverters httpMessageConverters(MyMappingJackson2HttpMessageConverter converter) {
return new HttpMessageConverters(converter);
}
public static class MyMappingJackson2HttpMessageConverter extends MappingJackson2HttpMessageConverter {
public MyMappingJackson2HttpMessageConverter() {
List<MediaType> mediaTypeList = new ArrayList<>(this.getSupportedMediaTypes());
mediaTypeList.add(MediaType.TEXT_PLAIN);
this.setSupportedMediaTypes(mediaTypeList);
}
}
}