简介
springcloud 302跨域的其中一种情况
分析
spring security会有自动配置的类,在单体项目的前提下,通常我们都会进行重写配置,但分服务之后或许有些项目并不需要有security的存在,但由于通用模块中经常会引入导致该服务也同步引入。
解决方法
那么方法就两种:
- 每次引入都独立exclude security模块;
- 启动类exclude自动配置类。
我选择2,毕竟懒。
流程
启动类新增:
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class})
例如:
package com.lewis.module.m2;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* 启动程序
*
* @author Lewis
*/
@MapperScan("com.lewis.**.mapper")
@EnableDiscoveryClient
@EnableFeignClients
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class})
public class LewisM2Application {
public static void main(String[] args) {
SpringApplication.run(LewisM2Application.class, args);
System.out.println("============================= Lewis's system [ lewis-module-m2 ] start success =============================\n");
}
}
留q:398529803