Skip to content

Commit

Permalink
Merge pull request #26 from hiparker/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
hiparker authored Feb 9, 2023
2 parents a314805 + 2fd718f commit 15eed42
Showing 1 changed file with 0 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,34 +61,10 @@ public void configurePathMatch(PathMatchConfigurer configurer) {
.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);
}
}

0 comments on commit 15eed42

Please sign in to comment.