为什么当我在自己的依赖项中添加spring-boot-starter-security时,我得到了未经授权的呼叫?
依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
我的控制器:
@Controller
public class MyController {
@GetMapping(value = "/test")
ResponseEntity<String> test() {
return new ResponseEntity<>("OK", HttpStatus.OK);
}
}
我的通话:http://localhost:8080/test
响应:
{
"timestamp": "2019-05-21T15:02:15.055+0000",
"status": 401,
"error": "Unauthorized",
"message": "Unauthorized",
"path": "/test"
}
我已经向我的application.yml添加了security.basic.enable = false,但是仍然没有成功:
security:
basic:
enable: false
我也添加了一个配置类:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().permitAll()
.and()
.csrf().disable()
.formLogin().disable();
}
}