Spring 3.2 cannot find @RestController
When php editor Xiaoxin used Spring 3.2, he discovered a common problem-the @RestController annotation could not be found. When using the @RestController annotation, you may encounter compilation errors or runtime errors, resulting in the inability to use the annotation normally. This problem may involve version compatibility or configuration issues, which require corresponding solutions and adjustments. In this article, we will explore the causes and solutions to this problem, and help readers solve the problem of not finding the @RestController annotation in Spring 3.2.
Question content
This is wired, I try to set @restcontroller but it can't find it Running from the intellij community 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>
and simple classes:
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 { }
There are also compilation errors:
[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)
Workaround
Is there any particular reason why you commented out the main Spring Boot starter dependency? Try reloading your project using Maven and check your external libraries folder in the project window to make sure you have the dependencies. RestController annotations are expected to be imported from org.springframework.web.bind.annotation.RestController
.
The above is the detailed content of Spring 3.2 cannot find @RestController. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In function inheritance, use "base class pointer" and "derived class pointer" to understand the inheritance mechanism: when the base class pointer points to the derived class object, upward transformation is performed and only the base class members are accessed. When a derived class pointer points to a base class object, a downward cast is performed (unsafe) and must be used with caution.

Notepad++ itself cannot run C language programs and requires an external compiler to compile and execute the code. In order to use an external compiler, you can follow the following steps to set it up: 1. Download and install the C language compiler; 2. Create a custom tool in Notepad++ and configure the compiler executable file path and parameters; 3. Create the C language program and save it with a .c file extension; 4. Select the C language program file and select a custom tool from the "Run" menu to compile; 5. View the compilation results and output a compilation error or success message. If the compilation is successful, an executable file will be generated.

The val keyword in Java is used to declare an immutable local variable, i.e. its value cannot be changed once assigned. Features are: Immutability: Once initialized, the val variable cannot be reassigned. Local scope: val variables are only visible within the block of code in which they are declared. Type inference: The Java compiler will infer the type of the val variable based on the assigned expression. Local variables only: val can only be used to declare local variables, not class fields or method parameters.

The shortcut keys for running Python code in Sublime Text are: Windows and Linux: Ctrl + BMac: Cmd + B Place the cursor in the code. Press the shortcut key. The code will be run using the system's default Python interpreter.

The const modifier indicates a constant and the value cannot be modified; the static modifier indicates the lifetime and scope of the variable. Data members modified by const cannot be modified after initialization. Variables modified by static are initialized when the program starts and destroyed when the program ends. They will exist even if there is no active object and can be accessed across functions. Local variables modified by const must be initialized when declared, while local variables modified by static can be initialized later. Const-modified class member variables must be initialized in the constructor or initialization list, and static-modified class member variables can be initialized outside the class.

The Eclipse navigation bar can be displayed via the menu: Window > Show View > Navigation Shortcut key: Ctrl + 3 (Windows) or Cmd + 3 (Mac) Right-click the workspace > Show View > Navigation The navigation bar contains the following functions: Project Resource Browser: Shows folders and files Package Resource Browser: Shows Java package structure Problem View: Shows compilation errors and warnings Task View: Shows tasks Search field: Searches for code and files Bookmark View: Marks lines of code for quick access

Solution to the "Error: Could not find or load main class" error in Eclipse: Check whether the main class exists and the path is correct. Verify that the main class is in the correct package and that public access allows Eclipse access. Check the classpath configuration to ensure that Eclipse can find the class file for the main class. Compile and fix the error that caused the main class to fail to load. Check the stack trace to identify the source of the problem. Compile from the command line using the javac command and check the error messages. Restart Eclipse to resolve potential issues.

Restrictions on function overloading include: parameter types and orders must be different (when the number of parameters is the same), and default parameters cannot be used to distinguish overloading. In addition, template functions and non-template functions cannot be overloaded, and template functions with different template specifications can be overloaded. It's worth noting that excessive use of function overloading can affect readability and debugging, the compiler searches from the most specific to the least specific function to resolve conflicts.