簡體   English   中英

未檢測到登錄頁面Spring Boot

[英]Not detecting login page spring boot

TL; DR

問題是,如果我執行類似http://localhost:8080/registerUser ,然后轉到http://localhost:8080/login ,然后登錄,它將重定向到http://localhost:8080/style.css ,但是我已經把.defaultSuccessUrl("home.html")放在了上面,並且如果我在第一個電話上登錄時可以使用它。 好像Spring嘗試加載CSS,並且它沒有滲透力或其他東西,然后當我登錄時嘗試,然后CSS起作用。

我在Spring項目中遇到加載CSS的問題,我在:

resources/static/styles.css

如果我不添加以下代碼行:

@Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/resources/**").anyRequest();
    }

anyRequest()可以達到目的,但是現在我可以像以前一樣調用登錄頁面

http://localhost:8080/login

該登錄名是Spring的默認格式,如果我刪除.anyRequest()它將顯示login但不會加載CSS。

我的全班課程如下:

public class BaseSecurityConfig extends WebSecurityConfigurerAdapter {

    //Configure Spring security's filter chain
    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/resources/**").anyRequest();
    }

    //Configure how requests are secured by interceptors
    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                // order matters. First the most specific, last anyRequest()
                .antMatchers("/static/**").permitAll()
                .antMatchers("/h2-console/**").permitAll()
                .mvcMatchers("/registerUser").permitAll()
                .antMatchers("/").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin() //a login form is showed when no authenticated request
                .defaultSuccessUrl("/home.html")
                .and()
                .httpBasic()
                .and()
                .rememberMe()
                .tokenValiditySeconds(2419200)
                .key("auctions")
                .and()
                .logout()
                .logoutSuccessUrl("/bye.html");
        http
                .csrf().disable()
                .headers()
                .frameOptions().disable();
    }
}

我想念的是什么?

編輯

在我的.html我這樣做:

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:form="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8" />
    <link rel="stylesheet" type="text/css" th:href="@{../style.css}"/>
    <title>pewLas</title>
</head>
<body>

關於你的問題

我看到了這篇文章,但是在哪里創建css文件夾? 哪個根?

請嘗試“ /resources/static/css/styles.css”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM