Welcome Guest.

2Answers

Cross-domain issues occur after the springboot project is deployed to tomcat

Asked by: Jerry Lewis 198 views IT February 23, 2019

Cross-domain issues occur after the springboot project is deployed to tomcat

2 Answers

  1. +2Votes  

    @Configurationpublic class CorsConfig {
        private CorsConfiguration buildConfig() {
            CorsConfiguration corsConfiguration = new CorsConfiguration();corsConfiguration.addAllowedOrigin("*");corsConfiguration.addAllowedHeader("*");corsConfiguration.addAllowedMethod("*");        return corsConfiguration;}
        @Beanpublic CorsFilter corsFilter() {
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();source.registerCorsConfiguration("/**", buildConfig());        return new CorsFilter(source);}
    }1-New configuration file, add Configuration annotation 2 – Test cross-domain request to pass, so far has solved the ajax cross-domain problem perfectly, is it very easy, the little friends are going to try it!!!

    Deborah Morris- February 23, 2019 |

  2. +6Votes  

    Change the packaging method to war. This is not to say, definitely change to the war configuration embedded in Tomcat. There are two ways to choose here: Method 1: Use the spring-boot built-in tomcat library, and specify The version you want to deploy to Tomcat <properties><tomcat.version>7.0.69</tomcat.version></properties><dependency><groupId>org.apache.tomcat</groupId>< artifactId>tomcat-juli</artifactId><version>${tomcat.version}</version></dependency>Method 2: Do not use the spring-boot built-in tomcat library (highly recommended this way!!)<!– Add this item when calling the war package, tell the spring-boot tomcat related jar package to use external, don’t hit it–><dependency><groupId>org.springframework.boot</groupId>< artifactId>spring-boot-starter-tomcat</artifactId><s Cope>provided</scope></dependency>maven-war-plugin (optional) is similar to maven-resources-plugin, when you have some custom packaging operations, such as having a non-standard directory file to get the war package There are either configuration files that reference variables in the pom. See the official documentation for specific usage: http://maven.apache.org/components/plugins/maven-war-plugin/

    Eric Martin- February 23, 2019 |