php小编小新在使用spring 3.2时,发现了一个常见的问题——找不到@restcontroller注解。在使用@restcontroller注解时,可能会遇到编译错误或运行时错误,导致无法正常使用该注解。这个问题可能涉及到版本兼容性或配置问题,需要进行相应的解决和调整。在本文中,我们将探讨这个问题的原因和解决方法,帮助读者解决spring 3.2中找不到@restcontroller注解的困扰。
问题内容
这是有线的,我尝试设置@restcontroller,但它找不到它从 intellij 社区 ide 运行pom.xml
4.0.0org.springframework.bootspring-boot-starter-parent3.2.2com.restservicerestservice0.0.1-snapshotrestservicerestservice17<!-- org.springframework.boot spring-boot-starter -->org.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-testtestorg.springframework.bootspring-boot-maven-plugin
登录后复制
和简单的类:
package com.restservice.restservice;import org.springframework.boot.springapplication;import org.springframework.boot.autoconfigure.springbootapplication;@springbootapplicationpublic class restserviceapplication { public static void main(string[] args) { springapplication.run(restserviceapplication.class, args); }}package com.restservice.restservice;@restcontroller还有编译错误:
[INFO] --- maven-compiler-plugin:3.11.0:compile (default-compile) @ restservice ---[INFO] Changes detected - recompiling the module! :source[INFO] Compiling 2 source files with javac [debug release 17] to targetclasses[INFO] -------------------------------------------------------------[ERROR] COMPILATION ERROR :[INFO] -------------------------------------------------------------[ERROR] /C:/dev/my/java/spring_applications/ReactiveSpringBootREST Service2/restservice/src/main/java/com/restservice/restservice/RestController.java:[4,2] incompatible types: com.restservice.restservice.RestController cannot be converted to java.lang.annotation.Annotation[INFO] 1 error[INFO] -------------------------------------------------------------[INFO] ------------------------------------------------------------------------[INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[INFO] Total time: 1.771 s[INFO] Finished at: 2024-02-01T17:45:04+02:00[INFO] ------------------------------------------------------------------------[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project restservice: Compilation failure[ERROR] /C:/dev/my/java/spring_applications/ReactiveSpringBootREST Service2/restservice/src/main/java/com/restservice/restservice/RestController.java:[4,2] incompatible types: com.restservice.restservice.RestController cannot be converted to java.lang.annotation.Annotation[ERROR][ERROR] -> [Help 1][ERROR][ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.[ERROR] Re-run Maven using the -X switch to enable full debug logging.[ERROR][ERROR] For more information about the errors and possible solutions, please read the following articles:[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException$ java -version java version "17.0.4.1" 2022-08-18 LTSJava(TM) SE Runtime Environment (build 17.0.4.1+1-LTS-2) Java HotSpot(TM) 64-Bit Server VM (build 17.0.4.1+1-LTS-2, mixed mode, sharing)登录后复制
解决方法
您注释掉主要 Spring Boot 启动器依赖项有什么特殊原因吗?尝试使用 Maven 重新加载您的项目,并在项目窗口中检查您的外部库文件夹以确保您具有依赖项。 RestController注解预计从org.springframework.web.bind.annotation.RestController导入。
以上就是Spring 3.2找不到@RestController的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2621997.html