java - log4j2 在servlet3.1下报错NoClassDefFoundError
PHPz
PHPz 2017-04-18 10:49:36
0
1
600

我的maven配置

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-web</artifactId>
            <version>2.8.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.8.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.8.1</version>
            <scope>compile</scope>
        </dependency>

然后我在main函数中调用一切正常

public class Test {
    private static final Logger LOGGER = LogManager.getLogger(Test.class);
    public static void main(String[] args) {
        LOGGER.error("cuo wu");
    }
}

但是在servlet中使用就会报错

@WebServlet(urlPatterns = "/index")
public class Test extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        final Logger LOGGER = LogManager.getLogger();
        LOGGER.error("aefaefe");
        resp.getWriter().write("hi");
    }
}

错误信息是

java.lang.NoClassDefFoundError: org/apache/logging/log4j/LogManager

希望有经验的大佬帮帮忙

PHPz
PHPz

学习是最好的投资!

reply all(1)
小葫芦

You can check whether the corresponding class file exists in the project's release directory

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template