Java日志无法解析

问题描述 投票:0回答:2

我正在 eclipse IDE 上研究 spring 项目。

我在“log.info( ... );”中遇到了“日志无法解析”错误

[在此处输入图像描述][1]

这些是我找到并研究过的解决方案,但没有成功。

  1. 检查Eclipse或STS安装路径不是英文
  2. “lombok.jar”重新安装
  3. 删除pom.xml中log4j的依赖中的'runtime'
  4. 删除并重新安装“.m2”文件夹
  5. 将“@log4j”更改为“@Slf4j”

我看到很多关于这个问题的帖子,但我无法解决。请帮我。 如果我需要上传更多代码,请告诉我,因为这是我第一次。 谢谢你

代码

..src/main/java/controller

    package org.zerock.controller;
    
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Date;
    
    import org.springframework.beans.propertyeditors.CustomDateEditor;
    import org.springframework.http.HttpHeaders;
    import org.springframework.http.HttpStatus;
    import org.springframework.http.ResponseEntity;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.WebDataBinder;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.InitBinder;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.multipart.MultipartFile;
    import org.zerock.domain.SampleDTO;
    import org.zerock.domain.SampleDTOList;
    import org.zerock.domain.TodoDTO;
    
    import lombok.extern.log4j.Log4j;
    
    @Controller
    @RequestMapping("/sample/*")
    @Log4j
    public class SampleController {
    
       @InitBinder 
       public void initBinder(WebDataBinder binder) {
       SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
       binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
       }
    
       @RequestMapping("")   
       public void basic() {
    
          **log.info("basic...................");** 
    
       }
    
       @RequestMapping(value = "/basic", method = { RequestMethod.GET, RequestMethod.POST })
       public void basicGet() {  
    
          **log.info("basic get...................");**
    
       }
    
       @GetMapping("/basicOnlyGet")
       public void basicGet2() {
    
          **log.info("basic get only get...................");**
    
       }
    
    }

pom.xml

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${org.slf4j-version}</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>${org.slf4j-version}</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>${org.slf4j-version}</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.16</version>
    <exclusions>
        <exclusion>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
        </exclusion>
        <exclusion>
            <groupId>javax.jms</groupId>
            <artifactId>jms</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.sun.jdmk</groupId>
            <artifactId>jmxtools</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.sun.jmx</groupId>
            <artifactId>jmxri</artifactId>
        </exclusion>
    </exclusions>
    <!--  <scope>runtime</scope>-->
</dependency>

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.22</version>
    <scope>provided</scope>
</dependency>

  [1]: https://i.stack.imgur.com/ocA0M.png
java spring maven spring-mvc lombok
2个回答
0
投票

删除log4j,org.slf4j依赖,只添加lombok依赖并使用@Slf4j作为注释我认为不会有错误


0
投票

转到 CMD 中 .m2 存储库中的 lombok jar 并执行命令 java -jar lombok version.jar ,将打开新的弹出窗口以在 eclipse 路径上安装特定的 jar,然后单击安装。然后去eclipse清理并构建项目。

© www.soinside.com 2019 - 2024. All rights reserved.