Springboot RestController is never used
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
When an IDE says a Spring Boot @RestController is "never used," it usually does not mean the controller is broken. It usually means the IDE is looking for ordinary Java call sites, while Spring discovers and invokes controllers indirectly through component scanning and HTTP request mapping.
Why the Warning Appears
A controller method is not normally called directly by your own code. Spring creates the application context, scans for beans, detects request mappings, and invokes the matching method when an HTTP request arrives.
This controller is perfectly valid even though no Java code calls it explicitly:
An IDE inspection can mark the class or method as unused because it is not seeing Spring's runtime wiring.
Make Sure the Controller Is Actually Discoverable
Even though the warning is often harmless, you should still verify that the controller is in a package scanned by Spring Boot.
The usual structure is:
If DemoApplication is in com.example.demo, Spring Boot scans that package and its subpackages by default. A controller under com.example.demo.api will be found. A controller under some unrelated package may not be.
Verify with a Real Endpoint
The fastest way to prove the controller is actually used is to run the app and call the endpoint.
If the response comes back, the controller is being discovered and invoked correctly regardless of the IDE warning.
You can also add a simple test:
That is a much better signal than an unused-code inspection.
When the Warning Does Point to a Real Problem
Sometimes the controller really is not active. Common causes include:
- The class is outside the component-scan path.
- '
spring-boot-starter-webis missing.' - The application is using a different web stack than expected.
- The request mapping path is wrong.
- The controller bean is excluded by configuration.
If curl returns 404, the issue is no longer just an IDE message. At that point, inspect package layout, starters, and request mappings.
Common Pitfalls
The most common mistake is deleting or refactoring a working controller just because the IDE says it is unused. Framework-managed entry points often look unused to static inspection tools.
Another issue is assuming the warning is always harmless. It is usually harmless, but you still need to confirm that the application can actually route requests to the controller.
Developers also sometimes place controllers in packages that are siblings of the main application package instead of children. Spring Boot's default scanning is package-based, so structure matters.
Finally, do not rely only on IDE coloring or inspections for framework behavior. Run the application, hit the endpoint, and add tests for critical mappings.
Summary
- '
@RestControllerclasses often look unused because Spring invokes them reflectively at runtime.' - The warning is usually an IDE inspection issue, not a Spring Boot bug.
- Confirm the controller is under the application's component-scan path.
- Test the endpoint with
curlorMockMvcinstead of trusting the unused warning. - Treat
404or missing mappings as real configuration problems, not just IDE noise.
Related reading
- springboot swagger3 Failed to load remote configuration.
- Springfox swagger not working in spring boot 2.2.0
- SSD anchors in Tensorflow detection API
- SSL certificate rejected trying to access GitHub over HTTPS behind firewall
- Springboot retryable not retrying
- SpringBoot Unable to find a single main class from the following candidates
- springboot Upgrade from 2.3.5.RELEASE to 2.4.1- ClassNotFoundException org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
- Springfox 3.0.0 is not working with Spring Boot 2.6.0

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.