zainali5120
2021-01-16 869769dedf8722109c944db9a5d9fac97591c2d3
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package com.xcong.excoin.configurations;
 
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.xcong.excoin.configurations.properties.AliOssProperties;
import com.xcong.excoin.configurations.security.UserAuthenticationArgumentResolver;
import com.xcong.excoin.utils.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.validation.MessageCodesResolver;
import org.springframework.validation.Validator;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * @author wzy
 * @date 2020-04-27 11:54
 **/
@SpringBootConfiguration
@Slf4j
public class WebMvcConfig implements WebMvcConfigurer {
 
    @Resource
    private AliOssProperties aliOssProperties;
 
 
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(new UserAuthenticationArgumentResolver());
    }
 
    @Override
    public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> list) {
 
    }
 
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> list) {
 
    }
 
    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> list) {
 
    }
 
    @Override
    public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> list) {
 
    }
 
    @Override
    public void extendHandlerExceptionResolvers(List<HandlerExceptionResolver> list) {
 
    }
 
    @Override
    public Validator getValidator() {
        return null;
    }
 
    @Override
    public MessageCodesResolver getMessageCodesResolver() {
        return null;
    }
 
    @Override
    public void configurePathMatch(PathMatchConfigurer pathMatchConfigurer) {
 
    }
 
    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer contentNegotiationConfigurer) {
 
    }
 
    @Override
    public void configureAsyncSupport(AsyncSupportConfigurer asyncSupportConfigurer) {
 
    }
 
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer defaultServletHandlerConfigurer) {
 
    }
 
    @Override
    public void addFormatters(FormatterRegistry formatterRegistry) {
 
    }
 
    @Override
    public void addInterceptors(InterceptorRegistry interceptorRegistry) {
 
    }
 
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry resourceHandlerRegistry) {
 
    }
 
    /**
     * 设置cors跨域支持
     *
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true).maxAge(3600);
    }
 
    @Override
    public void addViewControllers(ViewControllerRegistry viewControllerRegistry) {
 
    }
 
    @Override
    public void configureViewResolvers(ViewResolverRegistry viewResolverRegistry) {
 
    }
 
    @Bean
    public OSS ossClient() {
        return new OSSClientBuilder().build(aliOssProperties.getEndPoint(), aliOssProperties.getAccessKeyId(), aliOssProperties.getAccessKeySecret());
    }
 
//    @Bean
//    public SpringContextHolder springContextHolder() {
//        return new SpringContextHolder();
//    }
}