错误:日志生成器/apache. logging. logger. atDebug()日志生成器

x759pob2  于 2022-11-06  发布在  Apache
关注(0)|答案(1)|浏览(552)

当我尝试从前面导入一个文件到我的api时,抛出这个错误:org.apache.logging.log4j.Logger.atDebug()Lorg/apache/logging/log4j/LogBuilder
我pom.xml中只有这个log4j依赖项:

<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>

这是我的控制器:

@RestController
@RequestMapping(value = "/api/importacao", produces = { "application/json" })
@CrossOrigin("*")
public class ImportacaoController {

    @Autowired
    private VeiculoService veiculoService;

    @Autowired
    private ImportacaoService importService;

    @PostMapping("/uploadexcel")
    public ResponseEntity<String> salvarArquivo(@RequestParam("file") MultipartFile file) {
        String caminho = UUID.randomUUID() + "." + extrairExtensao(file.getOriginalFilename());

        try {
            List<Veiculo> veiculos = veiculoService.converteArquivo(file);
            veiculos = veiculoService.salvarVeiculos(veiculos);
            Files.copy(file.getInputStream(), Paths.get(caminho), StandardCopyOption.REPLACE_EXISTING);

            Importacao importacao = new Importacao(caminho, LocalDate.now());
            importacao = importService.salvarImportacao(importacao);
            return new ResponseEntity<>("{\"Arquivo carregado com sucesso!\"}", HttpStatus.OK);
        } catch (Exception e) {
            return new ResponseEntity<>("{\"Erro ao carregar o arquivo!\"}",
                    HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }

private String extrairExtensao(String nomeArquivo) {
    int i = nomeArquivo.lastIndexOf(".");
    return nomeArquivo.substring(i + 1);
}

先谢谢你了。

3pvhb19x

3pvhb19x1#

我看到一个帖子,解决了我的问题,只是把这个依赖关系:

<dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-to-slf4j</artifactId>
            <version>2.17.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.17.2</version>
        </dependency>

相关问题