Spring 3.2找不到@RestController
php小编小新在使用Spring 3.2时,发现了一个常见的问题——找不到@RestController注解。在使用@RestController注解时,可能会遇到编译错误或运行时错误,导致无法正常使用该注解。这个问题可能涉及到版本兼容性或配置问题,需要进行相应的解决和调整。在本文中,我们将探讨这个问题的原因和解决方法,帮助读者解决Spring 3.2中找不到@RestController注解的困扰。
问题内容
这是有线的,我尝试设置@restcontroller,但它找不到它 从 intellij 社区 ide 运行 pom.xml
<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>3.2.2</version> <relativepath/> <!-- lookup parent from repository --> </parent> <groupid>com.restservice</groupid> <artifactid>restservice</artifactid> <version>0.0.1-snapshot</version> <name>restservice</name> <description>restservice</description> <properties> <java.version>17</java.version> </properties> <dependencies> <!--<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> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> </project>
和简单的类:
package com.restservice.restservice; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.springbootapplication; @springbootapplication public class restserviceapplication { public static void main(string[] args) { springapplication.run(restserviceapplication.class, args); } } package com.restservice.restservice; @restcontroller <--- can't find it painted with red public class 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 target\classes [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 LTS Java(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的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

在函数继承中,使用“基类指针”和“派生类指针”来理解继承机制:基类指针指向派生类对象时,执行向上转型,只访问基类成员。派生类指针指向基类对象时,执行向下转型(不安全),必须谨慎使用。

Notepad++ 本身不能运行 C 语言程序,需要一个外部编译器来编译和执行代码。为了使用外部编译器,可以按以下步骤进行设置:1. 下载并安装 C 语言编译器;2. 在 Notepad++ 中创建自定义工具,将编译器可执行文件路径和参数配置好;3. 创建 C 语言程序并保存为 .c 文件扩展名;4. 选择 C 语言程序文件,从“运行”菜单中选择自定义工具进行编译;5. 查看编译结果,输出编译错误或成功消息。如果编译成功,将生成可执行文件。

Java 中的 val 关键字用于声明不可变的局部变量,即一旦赋值后无法更改其值。特点有:不可变性:一旦初始化,val 变量不能重新赋值。局部作用域:val 变量仅在声明它们的代码块内可见。类型推断:Java 编译器会根据赋值的表达式推断 val 变量的类型。仅限局部变量:val 只能用于声明局部变量,不能用于类字段或方法参数。

在 Sublime Text 中运行 Python 代码的快捷键为:Windows 和 Linux: Ctrl + BMac: Cmd + B将光标放置在代码中。按下快捷键。代码将使用系统默认的 Python 解释器运行。

const 修饰符表示常量,值不可修改;static 修饰符指示变量的生存期和作用域。const 修饰的数据成员在初始化后不可修改,static 修饰的变量在程序启动时初始化,在程序结束时销毁,即使没有活动对象也会存在,并且可以跨函数访问。const 修饰局部变量必须声明时初始化,static 修饰的局部变量可以稍后初始化。const 修饰类成员变量必须在构造函数或初始化列表中初始化,static 修饰的类成员变量可以在类外部初始化。

Eclipse 中出现 "Error: Could not find or load main class" 错误的解决方法:检查主类是否存在并路径正确。确认主类位于正确的包中,公共访问权限允许 Eclipse 访问。检查类路径配置以确保 Eclipse 能够找到主类的类文件。编译并修复导致无法加载主类的错误。检查堆栈跟踪以识别问题根源。使用 javac 命令从命令行编译并检查错误消息。重新启动 Eclipse 以解决潜在问题。

Eclipse 导航栏可通过以下方法显示:通过菜单:Window > Show View > Navigation快捷键:Ctrl + 3 (Windows) 或 Cmd + 3 (Mac)右键单击工作区 > Show View > Navigation导航栏包含以下功能:项目资源浏览器:显示文件夹和文件包资源浏览器:显示 Java 包结构问题视图:显示编译错误和警告任务视图:显示任务搜索字段:搜索代码和文件书签视图:标记代码行供快速访问

函数重载的限制包括:参数类型和顺序必须不同(相同参数个数时),不能使用默认参数区分重载。此外,模板函数和非模板函数不能重载,不同模板规范的模板函数可以重载。值得注意的是,过度使用函数重载会影响可读性和调试,编译器从最具体到最不具体的函数进行搜索以解决冲突。