【发布时间】:2020-08-25 05:47:08
【问题描述】:
我尝试在我的 Spring Boot 应用程序上配置 OpenFeign,我使用 pokeapi 进行测试。
我做这个代码:
@FeignClient(value = "pokeapi", url = "https://pokeapi.co")
public interface PokeApiClient {
@Headers("Content-Type: application/json")
@RequestMapping(method = RequestMethod.GET, value = "/api/v2/pokemon/{name}", consumes =
"application/json")
Optional<Pokemon> findPokemonByName(@PathVariable("name") String name);
}
但是当我进行此调用时,会发生此错误:feign.FeignException$Forbidden: [403 Forbidden] during [GET] to [https://pokeapi.co/api/v2/pokemon/ditto] [PokeApiClient#findPokemonByName(String)]: [error code: 1010]
在这种情况下我该怎么办?
我尝试用这个来配置 WebSecurity:
@Configuration
@EnableWebSecurity
public class HttpConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/**/authenticate").permitAll()
.antMatchers(HttpMethod.GET, "/**/get-public-key").permitAll()
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
.anyRequest().permitAll();
}
}
【问题讨论】:
标签: java spring spring-boot spring-mvc spring-cloud-feign