top of page
Jay Amipara

Important SpringBoot Annotations

1. @Bean

-The @Bean annotations are used at the method level and indicate that a method produces a bean that is to be managed by the Spring container. It is an alternative to the XML<bean> tag.

2. @Service

-It is used at the class level. It shows that the annotated class is a service class, such as business basic logic, and call external APIs.

3. @Repository

-It is a Data Access Object (DAO) that accesses the database directly. It indicates that the annotated class is a repository.

4. @Configuration

-It is used as a source of bean definitions. It is a class-level annotation.

-The configuration annotation represents the class having one or more @Bean methods. The spring container could go ahead and generate the Spring Beans to be used.

5. @Controller

-The annotation is used to indicate that the class is a web request handler. It is often used to present web pages. It is most commonly used with @RequestMapping annotation.

-The controller annotation indicates the class serves the role of a controller. The controller annotation is a specialisation of the component annotation where it is auto-detected through the classpath scanning.

6. @RequestMapping

-RequestMapping is used to map the HTTP request. It is used with the class as well as the method. It has many other optional elements like consumes, name, method, request, path, etc.

-Mostly we use @RequestMapping at class level, and at method level we use

-@GetMapping

-@PostMapping

-@DeleteMapping

7. @Autowired

- This annotation is used to auto-wire spring bean on setter methods, constructor and instance variable. It injects object dependency implicitly. When we use this annotation, the spring container auto-wires the bean by its matching data type

- The Autowired annotation is used to inject the dependency in the bean. The Autowired provides more control to the developers over where the Autowire should be used.

8. @Component

- It is a class-level annotation that turns the class into Spring bean at the auto-scan time.

- he component annotation can automatically detect custom beans. It represents that the framework could autodetect these classes for dependency injection.

9. @SpringBootApplication

- It consists of @Configuration, @ComponentScan, and @EnabeAutoConfiguration. The class annotated with @SpringBootApplication is kept in the base package. This annotation does the component scan. However, only the sub-packages are scanned.

10. @EnableautoConfirguration

- It is placed on the main application class. Based on classpath settings, other beans, and various property settings, this annotation instructs SpringBoot to start adding beans.

-The Enable Auto Configuration allows the spring boot to auto-figure the application context. The applications are auto figured basis the added jar dependencies.

62 views0 comments

Recent Posts

See All

Battle of the Backends: Java vs Node.js

Comparing Java and Node.js involves contrasting two distinct platforms commonly used in backend development. Here’s a breakdown of their...

Commenti


bottom of page