问题事故: SpringCloud 主服务加了security 登陆认证后,突然client客户端全部连接不上了?

解决办法:修改主服务启动类:

@SpringBootApplication
@EnableEurekaServer
public class NetworkBusServerApplication extends WebSecurityConfigurerAdapter{
    static Logger logger = LoggerFactory.getLogger(NetworkBusServerApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(NetworkBusServerApplication.class, args);
        logger.info("Springcloud 主服务启动完成!");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // Configure HttpSecurity as needed (e.g. enable http basic).
//        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
        http.csrf().disable();
        //注意:为了可以使用 http://${user}:${password}@${host}:${port}/eureka/ 这种方式登录,所以必须是httpBasic,
        // 如果是form方式,不能使用url格式登录
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();

    }

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐