Spring启动JSP错误:NoClassDefFoundError [英] Spring boot JSP error: NoClassDefFoundError

查看:91
本文介绍了Spring启动JSP错误:NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试运行配置了JSP的spring boot app时,我都会收到此错误:

Everytime I try to run spring boot app configured with JSP I get this error:

java.lang.NoClassDefFoundError: javax/servlet/ServletContext
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
.............
[more errors/exceptions]
.............
Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/ServletContext
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)

我试图运行样本: spring-boot-sample-web-jsp spring-boot-sample-web-jsp

这些样本的结果相同。我使用IntelliJ IDEA运行应用程序并且没有IDEA为什么它不起作用。

The result is the same for those samples. I run application using IntelliJ IDEA and have no IDEA why it does not work.

推荐答案

有一个 IntelliJ中的错误表示提供的依赖项未添加到类路径中。假设你想坚持使用IDEA,你有几个选择:

There's a bug in IntelliJ that means that provided dependencies aren't added to the classpath. Assuming you want to stick with IDEA, you have a few options:


  • 在IDEA中手动配置类路径

  • 使用命令行运行示例mvn spring-boot:run

  • 删除所有出现的< scope>从pom提供< / scope> 。这意味着应用程序无法部署为对Tomcat或类似的战争

  • Manually configure the classpath in IDEA
  • Run the samples on the command line using mvn spring-boot:run
  • Remove all occurrences of <scope>provided</scope> from the pom. This will mean that app can't be deployed as a war to Tomcat or similar

编辑:错误已修复且服务器将只要在 classpath 下面的运行配置中勾选 包含提供范围 的依赖项复选框,就可以正常启动strong>。

The bug is fixed and the server will start normally, as long as you tick the Include dependencies with "Provided" scope checkbox in the run configuration, below classpath.

这篇关于Spring启动JSP错误:NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆