我正在遵循此处的 Spring Security 指南,http://docs.spring.io/spring-security/site/docs/3.2.0.RELEASE/reference/htmlsingle/#jc-httpsecurity
我已将这些设置在我的 pom.xml
中
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
在我的安全配置类中
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
我有
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll();
}
HttpSecurity
有方法 formLogin
,但另一个调用以 authorizeRequests()
开头返回类型
org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer<org.springframework.security.config.annotation.web.builders.HttpSecurity>.ExpressionInterceptUrlRegistry
没有方法 formLogin
不再了。
知道我哪里出错了吗?
最佳答案
尝试更改顺序,使表单登录配置排在第一位:
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.authorizeRequests()
.anyRequest()
.authenticated();
}
编辑:将“.and”更改为“.and()”
关于java - Spring 安全 HttpSecurity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21117890/