我启用了Websecurity,但我启用了anyRequest()和permitAll()方法仍然在邮递员中收到此错误。下面是我在配置中的代码。
@EnableWebSecurity
@Configuration
public class SecurityConfifguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.authorizeRequests()
.anyRequest()
.permitAll()
.and().httpBasic().disable();
httpSecurity.csrf().disable();
}
}
以下是控制器代码
@RestController
@RequestMapping("/rest/hello")
public class HelloResource {
@GetMapping
public String hello() {
return "Hello World";
}
}
申请类
@ComponentScan
@SpringBootApplication
public class SpringSecurityExampleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringSecurityExampleApplication.class, args);
}
}
邮差错误
{
"timestamp": 1513867805556,
"status": 401,
"error": "Unauthorized",
"message": "Full authentication is required to access this resource",
"path": "/rest/hello"
}
推荐但是提示帮助
httpSecurity
.anonymous() //allow anonymous access
.and()
.authorizeRequests()
.antMatchers("**/rest/**").permitAll();
我希望它能回复“Hello World”。
第二次推荐,但没有帮助
httpSecurity
//some configuration
// .and()
.anonymous() //allow anonymous access
.and()
.authorizeRequests()
.antMatchers("/rest/**").permitAll();