Comprehensive Overview of Spring MVC, Bean, Dependency Injection, Scope, and Spring Boot Annotations
This article provides a detailed guide to the most commonly used Spring and Spring Boot annotations—including MVC mapping annotations, bean registration annotations, dependency injection and scope annotations, as well as conditional configuration annotations—explaining their purposes, key attributes, and example usages for Java backend development.
Spring MVC Annotations
The @RequestMapping annotation maps web requests to handler methods and supports attributes such as value , method , params , header , consume , and produce . It can be applied at the class level to prepend a base path to all methods. Shortcut annotations @GetMapping , @PostMapping , @PutMapping , @DeleteMapping and @PatchMapping are specialized forms of @RequestMapping for specific HTTP verbs.
Spring Bean Annotations
Annotations such as @Component , @Service , and @Repository mark classes for automatic detection and registration as Spring beans. @ComponentScan configures the packages to be scanned for these component annotations.
Dependency Injection and Scope
The @Autowired annotation injects dependencies and can be used on constructors, setters, or fields. When multiple beans of the same type exist, @Qualifier and @Primary help select the appropriate bean. @DependsOn forces bean initialization order. The @Bean annotation defines bean creation methods, with optional initMethod and destroyMethod callbacks. Bean lifecycles are controlled by @Scope , which supports scopes like singleton , prototype , request , session , and custom scopes.
Spring Boot Annotations
@SpringBootApplication combines @Configuration , @EnableAutoConfiguration , and @ComponentScan to bootstrap a Spring Boot application. Conditional annotations such as @ConditionalOnClass , @ConditionalOnMissingClass , @ConditionalOnBean , @ConditionalOnMissingBean , @ConditionalOnProperty , @ConditionalOnResource , @ConditionalOnWebApplication , @ConditionalOnNotWebApplication , @ConditionalExpression , and the generic @Conditional enable fine‑grained configuration based on classpath, bean presence, property values, resources, or custom expressions.
Summary
The article offers a comprehensive reference for developers, covering the purpose, key attributes, and practical examples of Spring MVC, bean, dependency‑injection, scope, and Spring Boot annotations, empowering them to build well‑structured and configurable Java backend applications.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.