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

我的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

学习是最好的投资!

全部回复(1)
小葫芦

可以在项目的发布目录下找一下对应的class文件是否存在

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板