Overview of Spring Web MVC, Bean, and Boot Annotations
This article provides a comprehensive guide to Spring MVC request‑mapping annotations, Spring Bean lifecycle and dependency‑injection annotations, as well as Spring Boot conditional and configuration annotations, illustrating each with code examples and usage notes for Java backend development.
The article introduces the purpose of @RequestMapping in Spring MVC and Spring WebFlux, explaining its six attributes ( value, method, params, header, consume, product) and the need to combine it with @Controller or @RestController.
It then presents examples of specific mapping shortcuts such as @GetMapping, @PostMapping, @PutMapping, @DeleteMapping, and @PatchMapping, each shown with an illustrative image.
The @RequestBody annotation is described as a way to bind HTTP request bodies to method parameters via HttpMessageConverter, with a sample usage image.
Further, the article covers controller‑level annotations: @ControllerAdvice (used with @ExceptionHandler, @InitBinder, @ModelAttribute), @ResponseBody (and its implicit inclusion in @RestController), @ExceptionHandler, @ResponseStatus, @PathVariable, and @RequestParam, each accompanied by example screenshots.
It then explains bean‑related annotations: @ComponentScan, @Component, @Service, @Repository, showing how they register classes in the Spring container.
Dependency‑injection annotations are detailed, including @Autowired (constructor, setter, field injection), @Primary, @PostConstruct, @PreDestroy, and @Qualifier, with corresponding code images.
Scope management is discussed via @Scope (singleton, prototype, request, session, globalSession) and the @Bean annotation’s initMethod and destroyMethod attributes, illustrated with code snippets.
Conditional configuration annotations for Spring Boot are presented: @ConditionalOnClass, @ConditionalOnMissingClass, @ConditionalOnBean, @ConditionalOnMissingBean, @ConditionalOnProperty, @ConditionalOnResource, @ConditionalOnWebApplication, @ConditionalOnNotWebApplication, @ConditionalExpression, and the generic @Conditional, each with brief example code.
Finally, the article summarizes the most common Spring Boot annotations— @SpringBootApplication, @EnableAutoConfiguration, and related conditional annotations—highlighting their role in auto‑configuration and component scanning, and ends with a concluding paragraph reminding readers of the overall coverage.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Code Ape Tech Column
Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn
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.
