Spring boot and MVC annotation list
@Autowired
To inject object of spring component class
@Qualifier
To inject object having same name or ambiguity of multiple spring components
@RestController
Define controller for rest endpoints
@Controller
Define controller for web routing
@RequestMapping
Define routing map and endpoints
@GetMapping
Define GET method endpoint for getting resource
@PostMapping
Define POST method endpoint for inserting new request
@DeleteMapping
Define DELETE method endpoint for delete request
@PutMapping
Define PUT method endpoint for update request
@RequestParam
Define input request parameter on request.
@PathVariable
Define input request parameter on request as query string to show on URL.
@ExceptionHandler
To handle exception. To route exception if raises to define class.
@ResponseStatus
To display response while calling resource method.
@Bean
Property or method to become part of spring container.
@Configuration
Class having beans method to make part of spring application.
@SpringBootApplication
Comnination of below 3 annotations. It is used to run spring boot applcation. It annotates on main method of application launcher class.
“@Configuration”
“@ComponentScan(“app”)
“@EnableWebMvc”
@CrossOrigin
Allowing request came from different source.
@ResponseBody
To return response as output object from method
@RequestBody
To get request object as input to method
@Component
Add class to spring container
@Service
Make class as service class for business logic
@Repository
Make class as repository for database operations like DAO
@EnableWebMvc
Enable application based on web MVC architecture
@ComponentScan
Scan packages where actual class reside and tell to spring container
@CrossOrigin
Enable controller to accept request from different origin
@NoArgsContructor
Its Lombok annotation means DTO have no argument constructor
@AllArgsContructor
Its Lombok annotation means DTO have argument constructor of all defined fields
@RequiredArgsConstructor
Its Lombok annotation means DTO have argument constructor of all the types
@Cleanup
Its Lombok annotation used to clean up the code automatically before execution
@ToString
Its Lombok annotation means DTO have to string method.
@EqualsAndHashCode
Its Lombok annotation used to generated and equals and hashcode method.
@NonNull
This annotation is referred as value must be not null
@Log
This annotation is used to log message in Slf4j
@Builder
Its Lombok annotation used to generated auto builder API for complex pojo class
@Data
Defined DTO or getter setter class.
@Getter
Used to get value on method.
@Setter
Used to set value on method.
@Slf4j
Enable Slf4j logging in class.
@Value
Used to get property value from properties file.
@Scope
This is used to defined scope by default scope is singleton you can define other scope as well
@RequestHeader
To fetch header value from request using map collection.
@ResponseHeader
Return response on method which is set on this annotation parameter.
@PropertySource
This annotation is used to provide properties file to spring environment that which should be follow.
@ModelAttributes
It is spring MVC base annotation used to store data from object and pass to view (JSP page) through controller.
@SessionAttributes
This annotation retrieve the existing attribute from the session. This annotation allows you to tell Spring which of your model attributes will also be copied to HttpSession before rendering the view.
@Table
If class name is different from database table name then database table name defined with this annotation.
@Entity
Refer class with database table.
@Column
Refer field name with database table column name.
@Id
Refer key column on database table.
@OneToOne
This annotation refers mapping with column of one table refers to one column of other table.
@OneToMany
This annotation refers mapping with column of one table refers to many column of other table.
@ManyToMany
This annotation refers mapping with many of one table refers to many column of other table.
@JoinColumn
This annotation defines that actual physical mapping on the owning side.
@Transactional
This is important annotation of spring transaction manager used in database DML transactions. It is used to rollback transaction if runtime exception occur during DML operations.
@Modify
Its JPA annotation used in service or repository class where we want to perform database manipulation operation.
@GeneratedValue
It is used in id field of class to map with table id field. It has parameter of strategy of how id is generated on every request.
@Synchronized
It is used to make method synchronized (Thread safe) just like synchronized keyword in java. It also exists on class and method level.
@Async
It is only existed on method level to call that method asynchronously. When calling method on async mode sperate thread is open that will not affect main thread.
@Secured
This annotation is used to specify a list of roles on a method. So, a user only can access that method if she has at least one of the specified roles.
@RolesAllowed
This is similar @Secured annotation where we passed defined role on method.
@PreAuthorize
The annotation can check for authorization before entering method. This authorizes on the basis of role or the argument which is passed to the method
@PostAuthorize
This annotation checks for authorization after method execution. This authorizes based on logged in roles, return object by method and passed argument to the method
@PreFilter
This annotation works in a very similar fashion; however, the filtering is applied to a list that is being passed as an input parameter to the annotated method.
@PostFilter
This annotation defines a rule for filtering the return list of a method, by applying that rule to every element in the list. If the evaluated value is true, the item will be kept in the list. Otherwise, the item will be removed.
@SpringBootTest
This annotation is primary to create unit and integration tests in Spring Boot applications.
@Test
This annotation used in method to test that method where it is used.
@Before
This annotation is used in Aspect-Oriented Programming to achieve the cross-cutting. It is an advice type which ensures that an advice runs before the method execution.
@After
This annotation is used in Aspect-Oriented Programming to achieve the cross-cutting. It is an advice type which ensures that an advice runs after the method execution.
@RunWith
This annotation takes parameter as class name provides a bridge between Spring Boot test features and JUnit. Whenever we are using any Spring Boot testing features in our JUnit tests, this annotation will be required.
@TestConfiguration
This annotation is a useful aid for writing unit tests of components in a Spring Boot application. It allows us to define additional beans or override existing beans in the Spring application context to add specialized configurations for testing.
@WebMvcTest
This annotation to fire up an application context that contains only the beans needed for testing a web controller:
@TestPropertySource
This is a class-level annotation that configures locations of property files and inclined properties in Spring integration test. The properties loaded by using this annotation are added to the set of @PropertySource in the Environment for an Application Context. The properties loaded by this annotation have higher precedence over the properties loaded from Java system properties