我正在尝试使用JavaConfig代替Spring配置的XML配置.我想@PreAuthorization用于声明访问权限.
我的Spring Security Config看起来像这样:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity( prePostEnabled = true )
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void registerAuthentication( AuthenticationManagerBuilder auth ) throws Exception {
auth
.inMemoryAuthentication()
.withUser( "user" ).password( "password" ).roles( "USER" );
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.部署Web应用程序后,我收到错误消息Error creating bean with name 'methodSecurityInterceptor' defined in class path resource.
经过一些研究,我发现我必须将aopalliance库添加到我的项目中.不幸的是,这并没有解决我的问题.
这是完整的堆栈跟踪:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodSecurityInterceptor' defined in class path resource [org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method …Run Code Online (Sandbox Code Playgroud) spring spring-security pre-authentication spring-java-config