包org.springframework.web.bind.annotation即使在POM中定义也不存在

时间:2017-09-07 04:30:36

标签: java spring maven spring-mvc spring-web

所以我有这个代码

import org.springframework.web.bind.annotation.GetMapping;

我的POM文件中已经有以下内容

<packaging>war</packaging>
    <properties>
        <spring.version>4.3.0.RELEASE</spring.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
    </dependencies>

然而,当我构建它最终抱怨包org.springframework.web.bind.annotation不存在

为什么呢?我已经添加了spring web作为依赖项。我做错了什么?

3 个答案:

答案 0 :(得分:12)

我遇到了类似的问题,我通过进入我的 pom.xml 文件并更改 spring boot 依赖项的 artifactID 来修复它:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
</dependency>

答案 1 :(得分:4)

运行以下命令

mvn clean install

如果您正在使用像intelliJ idea或Eclipse那样的IDE,请确保重新使用     导入项目。 以下是如何在eclipse中刷新maven依赖关系的答案

How to update maven repository in Eclipse?

答案 2 :(得分:0)

对我来说,删除spring-web依赖项是有效的。为此,请从pom.xml

中删除以下内容
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.version}</version>
</dependency>
相关问题