springboot启动报错(webSecurity匿名问题)

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘springSecurityFilterChain’ defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method ‘springSecurityFilterChain’ threw exception; nested exception is java.lang.IllegalStateException: An incomplete mapping was found for []. Try completing it with something like requestUrls()..hasRole(‘USER’)

在WebSecurityConfig(SecurityConfig)中配置

http.authorizeRequests()
//放行swagger
.antMatchers("/swagger-ui.html",
"/swagger-ui/*",
"/swagger-resources/**",
"/v2/**",
"/v3/**",
"/img.icons/**",
"/webjars/**",
"/doc.html").permitAll()
//只有匿名用户才能访问,其他都要登录
// 所有加 AnonymousAccess 注解的请求都允许匿名访问
.antMatchers(getAnonymousUrls()).anonymous();
//所有请求必须被认证(登录)
.anyRequest().authenticated();

方法一: antMatchers(getAnonymousUrls()).anonymous(); 和anyRequest().authenticated(); 同时有

方法二: antMatchers(getAnonymousUrls()).anonymous(); 和至少用一个方法上有@AnonymousAccess注解