Spring Boot注释@GetMapping无法解析为类型

问题描述 投票:0回答:2

我尝试在我的本地计算机上第一次从Spring Initializr创建一个Spring项目。但我收到这些错误@GetMapping无法解析为某种类型。

我们使用hml圆角

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>



<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

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

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

    </dependency>

    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>

</dependency>


    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

有人可以帮我弄这个吗?我缺少一些依赖吗?

spring spring-mvc spring-boot spring-web
2个回答
0
投票

我建议你从Spring Initalizr项目的https://start.spring.io/开始。你错过了这种依赖

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

0
投票

你有春季启动运行所需的所有依赖项,我使用了相同的pom并且它工作正常,几点:

  1. 如果你有 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>

然后不要求:

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

    </dependency>

    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>

</dependency>

您可以删除这些依赖项,因为启动器包含它。

  1. 还添加maven插件 <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>

然后从命令行运行:运行mvn clean install 3.然后尝试重建项目4.如果仍然无法工作,那么将starter-web作为第一个依赖项移动并再次检查。

© www.soinside.com 2019 - 2024. All rights reserved.