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("*");
                }
            };
        }
    }
  • 相关阅读:
    【原创】2013个人年终总结
    【原创】关于部门月会(二)
    【原创】关于部门月会(一)
    [转载]使用RoboCopy 命令
    ubuntu 16.04.3 安装完成后的一些初始化工作
    umbraco v7.6.4 surface controller not found 大深坑!
    ubuntu 及 postgredql 安装配置小坑摘录
    flex hack 记录
    C# 中的委托和事件
    OVER(PARTITION BY)函数介绍
  • 原文地址:https://www.cnblogs.com/jpit/p/8425827.html
Copyright © 2011-2022 走看看