无法在春天2.0.3解决@RestController注释

问题描述 投票:1回答:3

我想提出一个新的springboot- Maven项目。编译器不能当我用下面@RestController解决pom.xml

      <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
    </parent>

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

然而,当我修改版本1.5.13,该编译器能够解决@RestController

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.13.RELEASE</version>
    </parent>

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

我想使用最新版本的春天开机,并使用@RestController

java spring maven spring-boot spring-annotations
3个回答
2
投票

@RestController并非来自org.springframework.boot:spring-boot-starter-web,它来自org.springframework:spring-web。不同版本的弹簧引导启动的web大概必须有一些短暂的依赖,提供它,但它是一个不好的做法,依靠它。如果你在代码中使用@RestController,你应该明确地要求提供它的神器:

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

0
投票

因为我不能添加评论,我认为Maven的配置是不是你的问题,请检查您@Configuration和@SpringBootApplication类及其路径扫描设置

另外一个问题,你可以有:你的其他相关性,也许人们仍然依赖于春季启动1.5,你必须有一个干净的春天启动2.0类路径

我在这样的问题上运行一样,所以继续陷,你会发现它;-)


0
投票

我有几分类似的问题,这是因为我叫我的课RestController。有一次,我给它改名控制器,我可以导入@RestController包而不问题。

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