解決:SpringBoot項目訪問任意接口都跳轉到login登錄頁面

訪問項目的任意接口,都會跳轉到以下頁面

但是項目中,並沒有寫過前端的頁面。

想了想才發現,因爲項目中用到了SpringSecurity,而SpringSecurity默認給我們加了一個用戶認證的功能

用戶名是:user   密碼是在啓動的控制檯打印出來的:

解決方法: 

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfigSEVEN extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        //super.configure(http);
        //配置不需要登陸驗證
        http.authorizeRequests().anyRequest().permitAll().and().logout().permitAll();
    }

}

寫一個配置類,配置不需要登錄驗證就可以啦

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章