构建路径不完整。找不到 javax/servlet/ServletContext 的类文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16577535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 07:31:47  来源:igfitidea点击:

Build path is incomplete. Cannot find class file for javax/servlet/ServletContext

javaspringhibernate

提问by flutter

very new to java. Working on a CRUD hibernate spring project (sts). When configuring the xml file i get the error "Build path is incomplete.Cannot find class file for javax/servlet/ServletContext", by thebean id="viewResolver". How do I put this on the build path. cheers.

对 Java 非常陌生。从事 CRUD 休眠弹簧项目 (sts)。配置 xml 文件时,我收到错误“构建路径不完整。找不到 javax/servlet/ServletContext 的类文件”,由 thebean id="viewResolver" 提供。我如何将它放在构建路径上。干杯。

<context:annotation-config />
<context:component-scan base-package="com.ger" />   


<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
    p:location="/WEB-INF/jdbc.properties" />

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
    p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation">
        <value>classpath:hibernate.cfg.xml</value>
    </property>
    <property name="configurationClass">
        <value>org.hibernate.cfg.AnnotationConfiguration</value>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${jdbc.dialect}</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property> 
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean> 

回答by Jeevan Patil

Application seems to be missing one of the jars from servlet-api.jar, jsp-api.jar, el-api.jar, j2ee.jar, javaee.jar. And you don't need to copy and paste these into classpath. When application gets deployed on server, you will get those. You should above all never manually copy/download/move/include the individual servletcontainer-specific libraries.

应用程序似乎缺少servlet-api.jar, jsp-api.jar, el-api.jar, j2ee.jar,中的 jar 包之一javaee.jar。而且您不需要将这些复制并粘贴到类路径中。当应用程序部署在服务器上时,您将获得这些。最重要的是,您永远不要手动复制/下载/移动/包含单个 servletcontainer 特定的库。

If you are running this project from IDE, Check your server configurations.

如果您从 IDE 运行此项目,请检查您的服务器配置。

回答by Fuzzy Analysis

For WAR projects, this is a common error when you haven't moved the *.war file into the deployment folder... obviously the server can't find something it doesn't know about.

对于 WAR 项目,当您没有将 *.war 文件移动到部署文件夹时,这是一个常见错误……显然服务器找不到它不知道的东西。

If you are using an Eclipse-based IDE, simply right-click on the server you are deploying to in the "Servers" tab, then choose "Add and Remove", then move your .war file into the deployment folder. Restart your server and navigate to the URL to see if that fixes the issue.

如果您使用的是基于 Eclipse 的 IDE,只需在“服务器”选项卡中右键单击您要部署到的服务器,然后选择“添加和删除”,然后将您的 .war 文件移动到部署文件夹中。重新启动服务器并导航到 URL 以查看是否可以解决问题。

回答by Joshua Wilson

The problem is that the JIT in Eclipse does not work the same as the Java JDK that you can use on the command line with something like Maven. To fix this, just add the following to your pom.xml file.

问题是 Eclipse 中的 JIT 与 Java JDK 的工作方式不同,您可以在命令行上使用 Maven 之类的东西。要解决此问题,只需将以下内容添加到您的 pom.xml 文件中。

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

回答by razvanone

  • Windows 8.1, Maven 3.2.3
  • Spring STS 3.6.3.SR1
  • Maven Integration for Eclipse m2e 1.5.1.20150109
  • Spring IDE plugin 3.6.3.201411271034-RELEASE etc.
  • Windows 8.1,Maven 3.2.3
  • 弹簧 STS 3.6.3.SR1
  • Eclipse m2e 的 Maven 集成 1.5.1.20150109
  • Spring IDE 插件 3.6.3.201411271034-RELEASE 等

Had similar problem for several days. It said that some classes were missing from a dependent project (but they were present) that was opened and it was a Spring AOP plugin (?) problem. When closing the project, the dependency is seen correctly in the Maven repository. The problem is not observed when doing maven builds from the command line, only in STS.

有类似的问题好几天了。它说一些类从打开的依赖项目中丢失(但它们存在),这是一个 Spring AOP 插件(?)问题。关闭项目时,在 Maven 存储库中可以正确看到依赖项。从命令行执行 maven 构建时未观察到该问题,仅在 STS 中。

I tried various things. One of them, that it seem to work, is to open the applicationcontext.xml file with Spring Config Editor, go to the Namespaces tab, unselectthe context namespace, save (maybe do some cleanup), then select the context namespace, save again. Praying or dancing your favorite rain dance should help also :) The line where I saw this error was:

我尝试了各种事情。其中一个似乎有效的方法是使用 Spring Config Editor 打开 applicationcontext.xml 文件,转到 Namespaces 选项卡,取消选择上下文命名空间,保存(也许做一些清理),然后选择上下文命名空间,再次保存. 祈祷或跳你最喜欢的雨舞也应该有帮助:) 我看到这个错误的那一行是:

<context:component-scan base-package="aaa.bbb" />