【发布时间】:2015-01-16 08:34:02
【问题描述】:
我一直在努力解决这个问题有一段时间了。为了找到合适的解决方案,我已尽我所能,并遵循了很多 Stackoverflow 示例和解决方案。
首先,我使用的是基于注释的解决方案。当我注释我的服务时,prePostEnabled 有效,但当我注释控制器时,它不起作用。此外,即使在我的服务上,jsr250Enabled 也不起作用。
通过将注释从安全配置移动到 MVC 配置,我发现很多案例已关闭,这在我的案例中不起作用。
但我使用的是 Servlet 3.0,并且我的 web.xml 中没有任何内容。
我的 SecurityInitializer 如下所示:
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
}
我的 MVC 初始化程序如下所示:
public class MvcWebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{WebSecurityConfig.class, MethodSecurityConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{SpringMvcConfig.class};
}
@Override
protected String[] getServletMappings() {
return new String[]{ApiPaths.API + "/*", "/res.jsp"};
}
我的 WebSecurity 配置是这样初始化的:
@Configuration
@EnableWebSecurity
@ComponentScan(value = {"com.roler.res.**.server"}, excludeFilters = {
@Filter(type = FilterType.ASSIGNABLE_TYPE, value = SpringMvcConfig.class),
@Filter(type = FilterType.ASSIGNABLE_TYPE, value = MethodSecurityConfig.class),
@Filter(type = FilterType.REGEX, pattern = "com.xyz.*.controller.*")})
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
我的 SpringMvcConfig 是这样初始化的:
@Configuration
@EnableWebMvc
@ComponentScan(value = "com.xyz.**.controller")
public class SpringMvcConfig extends WebMvcConfigurerAdapter {
如果你有任何想法,我已经没有果汁了,谢谢!
【问题讨论】:
标签: spring-mvc spring-security