【问题标题】:I cant import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer我无法导入 org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer
【发布时间】:2014-08-27 19:03:17
【问题描述】:

我使用 Spring 工具套件创建了一个 Spring MVC Web 应用程序,我正在尝试创建这个类,但是当我执行 import 时出现此错误:

The import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer cannot be resolved

这是我要创建的类

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class WebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {      
}

我知道将WebApplicationInitializer 放到一个类中可能会产生一些问题,但是当我尝试使用另一个名称时,我得到了同样的错误。

这是我的 pom.xml 文件

<!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework-version}</version>
        <exclusions>
            <!-- Exclude Commons Logging in favor of SLF4j -->
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
             </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>

我的春季版本是 3.1.1。RELEASE 我的库中已经有 webmvc,但在我的支持中。“类列表”该类不存在我喜欢那里有 7 个类,但不是那个。

----已编辑

我将我的 spring 版本更新为 4.0.6 RELEASE,它知道该类出现在我的类路径 org.springframework.web.servlet.support 中。""

【问题讨论】:

  • 你的类路径中有那个类吗?
  • 如何在 spring 工具套件中查看我的类路径?
  • 查看构建路径,包含库。
  • 不,我没有,我查看了 org.springframework.web.servlet.support,我有 7 个类,但我想要的类不存在
  • 那你需要添加它。

标签: java spring spring-mvc import


【解决方案1】:

这个类从春天开始就被包含在春天里了version 3.2

如果您的 pom.xml 中的 version 低于此值,编译器将无法解析它。

【讨论】:

  • 是的,谢谢,我发现这也是问题所在,并于 2014 年 8 月 27 日发布并回答,但我的回答没有质量标准,因此被删除。不过还是谢谢朋友。
【解决方案2】:

org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer 类型是spring-webmvc 的一部分。您需要将该库作为依赖项添加到您的项目中。

【讨论】:

  • org.springframeworkspring-context${org.springframework-version} commons-loggingcommons-logging排除> org.springframeworkspring-webmvc${org.springframework-version}跨度>
【解决方案3】:

我的本​​地存储库中有两个 Spring 版本,删除旧版本后问题已解决。然后更新项目。

【讨论】:

    猜你喜欢
    • 2020-08-21
    • 2020-06-28
    • 2017-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-07
    • 1970-01-01
    • 2019-05-17
    相关资源
    最近更新 更多