- A+
所属分类:SpringCloud
---
title: "getForObject访问接口报错org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 null"
date: 2019-02-19 09:35:36
categories: SpringCloud
tags:
- null
- unauthorized
- getForObject
- RestTemplate
- antMatchers
- HttpClientErrorException
- 401
- 认证
- authorizeRequests
- permitAll
---
用restTemplate.getForObject访问认证服务器的接口/check/token时报错
org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 null
原因是配置文件里没有将/check/token加入例外,导致需要认证所以报401
解决方法将/check/token加入白名单即可。设置如下:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.requestMatchers()
.antMatchers("/login", "/check/token", "/oauth/authorize", "/oauth/token")
.and()
.authorizeRequests()
.antMatchers("/check/token")
.permitAll()
.anyRequest().authenticated()
.and()
.formLogin().permitAll();
}
