JAVA cross-domain, RestTemplate high concurrent abnormal configuration, JSON data transfer Long String

## cross-domain support import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; @Configuration public class CorsConfig {/ ** * Cross-Domain support * * @return * / @Bean public corsFilter corsFilter () {final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource (); final CorsConfiguration config = new CorsConfiguration (); config.setAllowCredentials (true); // allow cross-domain cookies config.addAllowedOrigin ( "*"); // # allowed to submit a request to the server URI, * represents all allowed config.addAllowedHeader ( "*" ); // # header information access is permitted, * means all config.setMaxAge (18000L); // preflight request buffer time (seconds), i.e., in this time period, the same request will not be cross-domain pre detecting the config.addAllowedMethod ( "*"); // the method allows to submit the request, * represents all allowed source. // Data read timeout time, i.e. SocketTimeout ms clientHttpRequestFactory.setReadTimeout (12000); // not enough latency connection, not too long, must be provided, such connection is not enough, too long would be disastrous clientHttpRequestFactory.setConnectionRequestTimeout (200); // buffer request data, the default value is true. By sending a POST or PUT a lot of data, it is recommended to change this property to false, so as not to run out of memory. // clientHttpRequestFactory.setBufferRequestBody (false); RestTemplate restTemplate = new RestTemplate (); restTemplate.setRequestFactory (clientHttpRequestFactory); restTemplate.setErrorHandler (new DefaultResponseErrorHandler ()); return restTemplate;}} ## json data is Long String / ** * * @description: return json is converted to long string * @create: 2019-08-02 17:49 ** / import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import org.springframework.context.annotation.Configuration; import org.springframework. > Converters) {MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter (); ObjectMapper objectMapper = new ObjectMapper (); / ** * time series into json, all because of the long string * into js obtained in all of the digital type can not contain long Java value * / simpleModule simpleModule = new simpleModule (); simpleModule.addSerializer (Long.class, ToStringSerializer.instance); simpleModule.addSerializer (Long.TYPE, ToStringSerializer.instance); objectMapper.registerModule (simpleModule); jackson2HttpMessageConverter.setObjectMapper (objectMapper) ; converters.add (jackson2HttpMessageConverter);}}> article by author pm1280415703: a Laboratory Manual release JAVA exchange group: 583 284 584!

Guess you like

Origin www.cnblogs.com/pm0101/p/11943501.html