Comprehensive Guide to Spring MVC, Spring Bean, and Spring Boot Annotations

This article provides a detailed overview of Spring MVC request‑mapping annotations, Spring Bean lifecycle and dependency‑injection annotations, as well as Spring Boot configuration annotations, illustrating each with explanations and code examples to help Java backend developers use these tools effectively.

Architecture Digest
Architecture Digest
Architecture Digest
Comprehensive Guide to Spring MVC, Spring Bean, and Spring Boot Annotations

1. Spring Web MVC Annotations

The @RequestMapping annotation maps HTTP requests to handler methods; it supports six attributes (value, method, params, header, consumes, produces) and can be applied at both class and method levels. Example usage:

@RequestMapping(value="/users", method=RequestMethod.GET, params="id")

Shortcut annotations such as @GetMapping, @PostMapping, @PutMapping, @DeleteMapping and @PatchMapping are equivalent to @RequestMapping with a specific HTTP method.

2. Spring Bean Annotations

Core component annotations include @Component, @Service, @Repository, and @Controller, which register classes as Spring beans. Scoping is controlled with @Scope, supporting singleton, prototype, request, session, etc. @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) Dependency injection is performed with @Autowired (field, setter, or constructor), optionally qualified by @Qualifier or prioritized with @Primary. Lifecycle callbacks use @PostConstruct and @PreDestroy.

3. Container‑Configuration Annotations

Exception handling and model binding are simplified with @ControllerAdvice, @ExceptionHandler, @ModelAttribute, and @ResponseBody. Cross‑origin support is added via @CrossOrigin, and data binding customization uses @InitBinder.

4. Spring Boot Annotations

The meta‑annotation @SpringBootApplication combines @Configuration, @EnableAutoConfiguration, and @ComponentScan, enabling rapid application setup.

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Conditional bean creation can be controlled with annotations such as @ConditionalOnClass, @ConditionalOnMissingBean, @ConditionalOnProperty, and others, allowing fine‑grained configuration based on classpath, bean presence, or property values.

Overall, the article serves as a reference sheet for developers to understand and correctly apply the wide range of Spring and Spring Boot annotations in modern Java backend projects.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaBackend DevelopmentspringSpring BootannotationsSpring MVC
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.