gpt4 book ai didi

Spring Security/j_spring_security_check 未找到 404

转载 作者:行者123 更新时间:2023-12-01 17:33:01 24 4
gpt4 key购买 nike

这是我的 WebAppInitializer:

@Configuration
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] { AppConfig.class, WebSecurityConfig.class };
}

@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { WebConfig.class };
}

@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}

这是我的安全配置:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private UserDetailsService userDetailsService;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
}

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

@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.authorizeRequests()
.antMatchers("/signup", "/about").permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and().formLogin().loginPage("/login").defaultSuccessUrl("/home").failureUrl("/error").permitAll()
.and().httpBasic();
// @formatter:on
}

}

这是我的login.html(来自thymeleaf的示例html):

<form th:action="@{/j_spring_security_check}" method="post">
<label for="j_username">Username</label>:
<input type="text" id="j_username" name="j_username" /> <br />

<label for="j_password">Password</label>:
<input type="password" id="j_password" name="j_password" /> <br />

<input type="submit" value="Log in" />
</form>

当我点击登录时,出现此错误:

HTTP ERROR 404

Problem accessing /j_spring_security_check. Reason:

Not Found

如何消除这个错误?我用谷歌搜索了很多,但还没有成功。 (是的,我不使用任何 xml。)

最佳答案

如果您使用的是 spring 4.X,则可能是版本问题

a.) login url = /login b.) logout url = /logout

如 spring 3.X 所示

a.) login url = /j_spring_security_check b.) logout url = /j_spring_security_logout

关于Spring Security/j_spring_security_check 未找到 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27469834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com