Spring Boot Annotations in Spring
Spring Boot Annotations in Spring
com/in/gangaraju-jalapinti-50b9621ab
Connect with me on LinkedIn: www.linkedin.com/in/gangaraju-jalapinti-50b9621ab
Component Scanning s
Dependency Injection
@Component : Marks a class as a Spring-
managed
component. Used for generic components that
don't fit into @Service, @Repository, or
@Controller categories.
@Controller : Specialized @Component, used
in Spring MVC to define a web controller.
@RestController : Combines @Controller and
@ResponseBody to simplify RESTful API
development.
@Service : Specialized @Component,
used for business logic and service layer
components.
@Repository : Specialized @Component, used
for data access objects (DAO) to indicate
storage operations.
@Autowired : Automatically injects
dependencies into Spring beans, reducing
manual configuration.
@Qualifier("beanName") : Specifies
which bean to inject when multiple
candidates exist.
@Primary : Marks a bean as the default
choice when multiple candidates exist.
@Value("${property.key}") : Injects
1
Connect with me on LinkedIn: www.linkedin.com/in/gangaraju-jalapinti-50b9621ab
2
Connect with me on LinkedIn: www.linkedin.com/in/gangaraju-jalapinti-50b9621ab
Configuration s Bean
Management
@Configuration : Marks a class as a
source of bean definitions for the Spring
container.
@Bean : Declares a method that produces
a Spring- managed bean.
@Import({ConfigClass.class}) :
Imports another configuration class.
@ImportResource("classpath:config.xml")
: Loads an XML configuration file.
@DependsOn("beanName") : Ensures a bean
is
initialized only after specific dependencies are
available.
@Lazy : Postpones bean initialization until
it is first accessed.
@Scope("prototype") : Defines bean scope
(singleton, prototype, etc.).
@PropertySource("classpath:app.propertie
s") : Loads external property files.
@EnableAspectJAutoProxy : Enables
support for Aspect-Oriented Programming
(AOP) in Spring.
Execution
Scheduled(cron="0 0 * * * ?") : Schedules a
method to run at a fixed interval.
@Async : Marks a method for asynchronous
execution.
4
Connect with me on LinkedIn: www.linkedin.com/in/gangaraju-jalapinti-50b9621ab
and @ComponentScan.
@EnableAutoConfiguration : Enables
Spring Boot’s auto-configuration.
@ComponentScan("com.example") : Scans
packages for Spring components.
6
Connect with me on LinkedIn: www.linkedin.com/in/gangaraju-jalapinti-50b9621ab
8
Connect with me on LinkedIn: www.linkedin.com/in/gangaraju-jalapinti-50b9621ab
Exception Handling
@ExceptionHandler(Exception.class) :
Catches exceptions at the controller level.
@ResponseStatus(HttpStatus.NOT_FOUND
) : Defines HTTP response status codes.
@ControllerAdvice : Defines global exception
handling logic for multiple controllers.
1
0
Connect with me on LinkedIn: www.linkedin.com/in/gangaraju-jalapinti-50b9621ab
Spring Caching
@EnableCaching : Enables caching in Spring.
@Cacheable("cacheName") : Caches method
results.
@CachePut("cacheName") : Updates cache
with fresh data.
@CacheEvict("cacheName") : Removes
entries from cache.
@CacheConfig(cacheNames={"default
Cache"}) : Configures caching settings at
the class level.
1
1
Connect with me on LinkedIn: www.linkedin.com/in/gangaraju-jalapinti-50b9621ab
Spring Security
@EnableWebSecurity : Enables Spring
Security configuration.
@Secured("ROLE_ADMIN") : Secures
methods based on roles.
@RolesAllowed({"ROLE_USER",
"ROLE_ADMIN"}) : Defines allowed roles.
@AuthenticationPrincipal : Injects the
authenticated user.
@PreFilter : Filters method arguments before
method execution.
@PostFilter : Filters the method return
value after method execution.
@PreAuthorize("hasRole('ROLE_USER')") :
Performs pre- execution authorization based on
roles.
@PostAuthorize("returnObject.owner ==
authentication
.name") : Performs post-execution authorization.
1
3
Connect with me on LinkedIn: www.linkedin.com/in/gangaraju-jalapinti-50b9621ab
side of a relationship.
1
5
Connect with me on LinkedIn: www.linkedin.com/in/gangaraju-jalapinti-50b9621ab
Repository s Transactions
@Transactional : Manages transactions at
the method or class level.
@Query("SELECT u FROM User u WHERE
u.email = ?1") : Custom JPA queries.
@Modifying : Used for update/delete queries.
@EnableJpaRepositories : Enables Spring
Data JPA repositories.
@Param: Binds method parameters to query
parameters in @Query.
1
6
Connect with me on LinkedIn: www.linkedin.com/in/gangaraju-jalapinti-50b9621ab
Gangaraju Jalapinti
Software Engineer | Java Specialist
LinkedIn: linkedin.com/in/gangaraju-
jalapinti-50b9621ab
Email:
[email protected]
Skilled Software Engineer with 1 year of experience in designing and developing secure,
scalable RESTful applications using Spring Boot and Microservices architecture. Adept in
Java 8 features, Hibernate, Oracle SQL, and API integration, with strong knowledge of
backend development patterns and enterprise application design
See You
1
7