java.util.MissingFormatArgumentException: 格式说明符“%s”

java.util.MissingFormatArgumentException: Format specifier '%s'

我显然遗漏了一些东西,但我不知道是什么...
愚蠢的是,有多少小事情比复杂的事情更能让你发疯...

这是控制器的代码:

    @RequestMapping(value = "/getClienteNomeCognome", method = RequestMethod.GET)
public ResponseEntity<List<Object>> getClienteNomeCognome(@RequestParam("nomeCliente") String nomeCliente,
        @RequestParam("cognomeCliente") String cognomeCliente) {
    List<Object> listaRisultati = new ArrayList<Object>();
    try {
        listaRisultati = serviziDocumentaleService.getClienteNomeCognome(nomeCliente, cognomeCliente);
    } catch (Exception e) {
        LOGGER.warn(String.format("Errore inatteso sulla chiamata del servizio: [%s]", e.toString()));
    }
    LOGGER.info(String.format("Avvio ricerca cliente con nome: %s, cognome: %s)", nomeCliente, cognomeCliente));
    return new ResponseEntity<List<Object>>(listaRisultati, HttpStatus.OK);
}

这是 getClienteNomeCognome:

    public List<Object> getClienteNomeCognome(String nome, String cognome) throws Exception {
    try {
        final RestTemplate restTemplate = new RestTemplate();
        final String url = "somelink?cognome=%25"+cognome+"%25&nome=%25"+nome+"%25";
        final ResponseEntity<List> response = (ResponseEntity<List>) restTemplate.getForObject(url, List.class);
        if (response.getBody() != null && response.getBody().toString().contains("<error>")) {
            throw new Exception(String.format(
                    "La risposta del servizio contiene degli errori: %s",
                    response.getBody()));
        } else {
            LOGGER.debug("Fine chiamata al servizio di ricerca cliente");
            return response.getBody();
        }
    } catch (HttpClientErrorException hcee) {
        throw new Exception(String.format(
                "Errore durante la chiamata. Error: %s",
                hcee.getMessage()));
    } catch (Exception e) {
        throw new Exception(String.format(
                "Errore generico durante la chiamata al servizio. Error: %s"
                        + e.getMessage()));
    }

}

我不能 100% 确定这个问题,因为它缺少代码,所以我可以从这里模拟它。但它看起来像:

LOGGER.info(String.format("Avvio ricerca cliente con nome: %s, cognome: %s)", nomeCliente, cognomeCliente));

在最后一个 %s 之后多了一个 ),所以可能只是没有正确读取它?除非在此处复制粘贴代码时出现错误。

如果可行,请告诉我们。

throw new Exception(String.format("Errore generico durante la chiamata al servizio. Error: %s" + e.getMessage()));

should be

throw new Exception(String.format("Errore generico durante la chiamata al servizio. Error: %s", e.getMessage()));