zoukankan      html  css  js  c++  java
  • SPRING BOOT跨域支持

    package com.example;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
    import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
    import org.springframework.context.ConfigurableApplicationContext;
    import org.springframework.context.annotation.Bean;
    import org.springframework.web.servlet.config.annotation.CorsRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
    
    
    public class SpringDemoApplication {
        
        static Logger logger = LoggerFactory.getLogger(SpringDemoApplication.class);
        
        public static void main(String[] args) {
            logger.debug(">>>>>>>>application starting...");
            ConfigurableApplicationContext ctx = SpringApplication.run(ZwylAppApplication.class, args);
            logger.debug(">>>>>>>>" + ctx.getApplicationName() + "---app application start success...");
        }    
        
        @Bean
        public EmbeddedServletContainerCustomizer containerCustomizer(){
               return new EmbeddedServletContainerCustomizer() {
                   @Override
                   public void customize(ConfigurableEmbeddedServletContainer container) {
                        container.setSessionTimeout(3600);
                  }
            };
        }
        
        @Bean
        public WebMvcConfigurer corsConfigurer() {
            return new WebMvcConfigurerAdapter() {
                @Override
                public void addCorsMappings(CorsRegistry registry) {
                    registry.addMapping("/**")
                    .allowedHeaders("*")
                    .allowedMethods("*")
                    .allowedOrigins("*");
                }
            };
        }
    }
  • 相关阅读:
    JAVA的HashTable源码分析
    散列表
    JAVA的HashSet源码分析
    Java中HashMap源码分析
    MySQL max_allowed_packet设置及问题
    通过分析 JDK 源代码研究 TreeMap 红黑树算法实
    红黑树详解
    TreeMap源码分析
    Vector的浅析
    web.xml 配置中classpath: 与classpath*:的区别
  • 原文地址:https://www.cnblogs.com/jpit/p/8425827.html
Copyright © 2011-2022 走看看