问题描述
我在下面提到的代码中得到 NullPointerException
的 httpClient
:
@Introspected
public class CustomEventHandler extends MicronautRequestHandler<Map<String,Object>,APIGatewayV2HTTPResponse> {
private static final Logger LOGGER = LoggerFactory.getLogger(CustomEventHandler.class);
@Inject
@Client("/")
public final RxHttpClient httpClient;
@Override
public APIGatewayV2HTTPResponse execute(Map<String,Object> input) {
String result = httpClient.toBlocking()
.retrieve(HttpRequest
.GET("http://test-api.com"));
final TestDto testDto;
try {
testDto = new ObjectMapper().readValue(result,TestDto.class);
return APIGatewayV2HTTPResponse.builder().withStatusCode(HttpStatus.SC_OK)
.withBody(testDto.toString())
.build();
} catch (JsonProcessingException e) {
e.printstacktrace();
}
return APIGatewayV2HTTPResponse.builder().withStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
.build();
}
}