要定制您的特定用例,请按照建议应用倒置逻辑。您可以这样:
1)更换
.anyRequest().authenticated()
通过
.anyRequest().anonymous()
2)添加
.antMatchers("/protected-urls/**").authenticated()由于首先匹配,因此2)中的规则必须先于1)中的规则。除非您为受保护的资源使用通用的URL前缀,否则必须一一声明所有经过身份验证的URL。
您还可以应用其他配置来覆盖
public void configure(WebSecurity web)...
例如忽略静态资源:
web.ignoring().antMatchers("/favicon.ico", "*.css")希望能有所帮助。



