Category: Spring Framework
Automatically Discover Beans with Auto Component Scanning
You can define your spring beans manually or let spring automatically discover stereotyped classes and register corresponding bean definitions with the application context. Spring scans for special marker annotations, which allows spring to auto-detect...
Creating and Configuring Custom @Qualifier Annotation
When Handling Multiple Dependencies with @Primary or Handling Multiple Dependencies with @Qualifier are not sufficient or you want to create your own custom @Qualifier Annotations for some reason. Spring allows you to create your...
Handling Multiple Autowire Candidates with Spring @Qualifier
Handling multiple autowire candidates with @Primary is effective when only one primary candidate can be determined for multiple autowire candidates. When you need more control over the selection process, you can use spring @Qualifier...
Handling Multiple Autowire Candidates with Spring @Primary
In spring, dependency injection is done default by type, this means that when there are multiple dependencies with the same type a NoUniqueBeanDefinitionException exception will be thrown. Indicating that only one candidate can be...
Spring Lifecycle Default Initialization and Destroy Methods
When working on a project with many team members, it is good to have some conventions. One of this conventions could be that you agree to use the same method name for initialization and...
Spring Lifecycle @PostConstruct and @PreDestroy annotations
The @PostConstruct and @PreDestroy are standard Java JSR-250 lifecycle annotations. Spring supports these annotations using the CommonAnnotationBeanPostProcessor. By annotation void no-argument signature methods with these annotations, your methods are eligible for initialization and destruction...
Spring Lifecycle InitializingBean and DisposableBean
The InitializingBean and DisposableBean can be used to interact with the spring container’s management lifecycle. The container calls the afterPropertiesSet() and the destroy() methods respectively to perform some actions upon initialization and destruction of...
Spring Lifecycle init-method and destroy-method
You can initialize or destroy your singleton bean using the xml configuration attributes init-method and destroy-method respectively. You must specify the name of the method that has a void no-argument signature. These methods will...
Gracefully Shutdown Spring Application Container
This tutorial shows you how to register a shutdown hook with the JVM in a non-web application context. By default the ApplicationContext does not have a shutdown hook and does not have any exposed...