首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

在没有http auto config的情况下直接配置spring security后找不到"j_spring_security_check"

在没有HTTP Auto Config的情况下,配置Spring Security后找不到"j_spring_security_check",这是因为在Spring Security中,"j_spring_security_check"是默认的登录处理URL,但在配置Spring Security时,如果没有使用HTTP Auto Config,则需要手动配置这个URL。

以下是手动配置"j_spring_security_check"的方法:

  1. 在Spring Security配置类中,继承WebSecurityConfigurerAdapter,并重写configure方法。
代码语言:java
复制
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/login").permitAll()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .loginProcessingUrl("/j_spring_security_check")
                .defaultSuccessURL("/", true)
                .permitAll();
    }
}
  1. 在上述代码中,使用.formLogin()方法配置登录页面的URL,并使用.loginProcessingUrl()方法配置登录处理URL为"j_spring_security_check"。
  2. 在登录页面中,确保表单的action属性指向"j_spring_security_check"。
代码语言:html
复制
<form name="loginForm" action="/j_spring_security_check" method="post">
   <label for="username">Username:</label>
   <input type="text" id="username" name="username" />
   <label for="password">Password:</label>
   <input type="password" id="password" name="password" />
   <input type="submit" value="Login" />
</form>
  1. 确保登录页面和登录处理URL都可以访问。

现在,当用户访问登录页面并提交登录表单时,Spring Security将处理请求并将其重定向到正确的URL。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

  • 什么是Spring Boot

    logging.config= # Location of the logging configuration file. For instance classpath:logback.xml for Logback logging.exception-conversion-word=%wEx # Conversion word used when logging exceptions. logging.file= # Log file name. For instance myapp.log logging.level.*= # Log levels severity mapping. For instance logging.level.org.springframework=DEBUG logging.path= # Location of the log file. For instance /var/log logging.pattern.console= # Appender pattern for output to the console. Only supported with the default logback setup. logging.pattern.file= # Appender pattern for output to the file. Only supported with the default logback setup. logging.pattern.level= # Appender pattern for log level (default %5p). Only supported with the default logback setup. logging.register-shutdown-hook=false # Register a shutdown hook for the logging system when it is initialized.

    05
    领券