Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

log4j2 在servlet3.1下报错NoClassDefFoundError

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

希望有经验的大佬帮帮忙


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...