|
|
|
@ -15,22 +15,13 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.opsli.core.autoconfigure.conf;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.opsli.common.annotation.ApiRestController;
|
|
|
|
|
import org.opsli.core.api.ApiRequestMappingHandlerMapping;
|
|
|
|
|
import org.opsli.core.autoconfigure.properties.ApiPathProperties;
|
|
|
|
|
import org.opsli.core.filters.interceptor.UserAuthInterceptor;
|
|
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
|
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
|
|
import org.springframework.web.cors.CorsConfiguration;
|
|
|
|
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
|
|
|
import org.springframework.web.filter.CorsFilter;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
@ -70,34 +61,10 @@ public class SpringWebMvcConfig implements WebMvcConfigurer, WebMvcRegistrations
|
|
|
|
|
.addPathPrefix(apiPathProperties.getGlobalPrefix(),c -> c.isAnnotationPresent(ApiRestController.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解决跨域问题
|
|
|
|
|
*
|
|
|
|
|
* @param registry registry
|
|
|
|
|
*/
|
|
|
|
|
// @Override
|
|
|
|
|
// public void addCorsMappings(CorsRegistry registry) {
|
|
|
|
|
// registry.addMapping("/**")
|
|
|
|
|
// .allowedOriginPatterns("*")
|
|
|
|
|
// .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
|
|
|
|
|
// .allowedHeaders("*")
|
|
|
|
|
// .allowCredentials(true)
|
|
|
|
|
// .maxAge(7200);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
|
|
// 加载特定拦截器
|
|
|
|
|
registry.addInterceptor(new UserAuthInterceptor());
|
|
|
|
|
WebMvcConfigurer.super.addInterceptors(registry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public MappingJackson2HttpMessageConverter getMappingJackson2HttpMessageConverter() {
|
|
|
|
|
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
|
|
|
|
.serializerByType(Long.class, ToStringSerializer.instance)
|
|
|
|
|
.serializerByType(Long.TYPE, ToStringSerializer.instance)
|
|
|
|
|
.build();
|
|
|
|
|
return new MappingJackson2HttpMessageConverter(objectMapper);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|