SpringBoot Annotation
SpringBoot Annotation
Java
SpringBoot Annotation
Annotation on Main Class @techwithvishalraj
import
Indicate the main configuration class of a Spring Boot
@SpringBoot org.springframework
application. It combines (@Configuration +
Application .boot.autoconfigure
@EnableAutoConfiguration + @ComponentScan)
.SpringBootApplication;
import
It is a class-level annotation. The class annotated
org.springframework
@Configuration with @Configuration used by Spring Containers as a
.context.annotation
source of bean definitions.
.Configuration;
import
@EnableAuto org.springframework It auto-configures the bean that is present in the
Configuration .boot.autoconfigure classpath and configures it to run the methods.
.EnableAutoConfiguration;
Annotation on Bean
import
Validation is commonly used to check user input,
@Validated org.springframework.validation.
validate data from external sources
annotation.Validated;
Annotation on Object
import
It is used to bind HTTP request with an
@RequestBody org.springframework.web
object in a method parameter.
.bind.annotation.RequestBody;
@PathVariable import
used to extract values from the URI path
("email") org.springframework.web.bind.
and use them as method parameters
annotation.PathVariable;
Annotation on DTO
@NotNull, @Email
@Size(min = 2, max = 50) import
apply validation constraints to fields.
@Pattern(regexp = "[a-z]", javax.validation.constraints.*;
message = "abc”)
Annotation on Entity/Model @techwithvishalraj
import
@Id Specifies the primary key of the entity.
javax.persistence.Id;
@OneToMany
import javax.persistence.*; Define relationships between entities.
@OneToOne
@Service(value= import org.springframework It is used at class level. It tells the Spring that
"xyzXyz") .stereotype.Service; class contains the business logic.
Transactional Annotation
MethodArgumentNotValidException exception is
typically thrown when validating the request
import parameters, request body, or method arguments
org.springframework.we of a controller endpoint using annotation-based
@ExceptionHandler({
b.bind.MethodArgument validation (e.g., @Valid and validation
MethodArgumentNot
NotValidException; annotations like @NotNull, @Size, etc.).
ValidException.class,
ConstraintViolationException exception is more
ConstraintViolation
import closely associated with Bean Validation and is
Exception.class})
javax.validation.Constrai thrown when there are validation constraints
ntViolationException; violated on JavaBeans. These constraints are
typically defined using annotations like
@NotNull, @Size, @Email, etc.
Test Annotation
EXPLORE MORE
@techwithvishalraj