log4j2 - 未解析的符号调试

log4j2 - unresolved symbol debug

这正在使用(或者说试图使用)servlets 2.5 和 log4j 2.1

logger.debug("test") 行生成无法解析符号调试。

我有点迷茫,因为据我所知,我已经遵循了所有文档?

    package myPkg;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.web.WebLoggerContextUtils;

@Path("myresource")
public class MyResource {
    final Logger logger = LogManager.getLogger(MyResource.class);
    logger.debug("test");

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getIt() {
        return "Got it!";
    }
}

我已经根据文档在 web.xml 中实现了更改,相关摘录如下:

   <!-- log4j-->
    <listener>
        <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
    </listener>

    <filter>
        <filter-name>log4jServletFilter</filter-name>
        <filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>log4jServletFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>
    <!-- end log4j-->

我的 log4j pom.xml 看起来像

 <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-web</artifactId>
            <version>${log4j.version}</version>
        </dependency>

编译时错误:

(18,17) java:预期 (18,18) java: 类型

的非法开始

代码"logger.debug("测试");"应该在一个方法、一个构造函数或至少一个静态块中,像这样:

public class A {
    {
        logger.debug("test");
    }
}