Learn SpringFrameWork5 - vidyasekaran/current_learning GitHub Wiki
https://howtodoinjava.com/spring-core/spring-bean-life-cycle/
and code set using https://www.javaguides.net/2018/10/spring-initializingbean-and-disposablebean-example.html
Local code setup : E:\learn_springframework5\spring-core-tutorial-master https://github.com/vidyasekaran/spring-core-tutorial
spring-bean-life-cycle
Spring framework provides following 4 ways for controlling life cycle events of a bean:
-
InitializingBean and DisposableBean callback interfaces
https://www.javaguides.net/2018/10/spring-initializingbean-and-disposablebean-example.html E:\learn_springframework5\spring-core-tutorial-master\spring-bean-lifecycle https://github.com/vidyasekaran/spring-core-tutorial/spring-bean-lifecycle/
-
Aware interfaces for specific behavior
Spring offers a range of *Aware interfaces that allow beans to indicate to the container that they require a certain infrastructure dependency. Each interface will require you to implement a method to inject the dependency in bean.
Important ones are listed below ResourceLoadAware example : https://howtodoinjava.com/spring-core/spring-resource-loader-aware/
Spring provides following 6 implementations for the Resource interface.
a. UrlResource b. ClassPathResource c. FileSystemResource d. ServletContextResource e. InputStreamResource f. ByteArrayResource
For complete resource load demo : https://github.com/spring-framework-guru/sfg-blog-posts/tree/master/resourceloaderdemo - this eads file from url,classpath, system folder
Local : E:\learn_springframework5\spring-core-tutorial-master\spring-bean-lifecycle\src\main\java\net\javaguides\spring\Application.java
- Custom init() and destroy() methods in bean configuration file
- @PostConstruct and @PreDestroy annotations
Spring Dependency Injection git : https://github.com/RameshMF/spring-core-tutorial
https://www.javaguides.net/p/spring-tutorial-beginners-to-expert.html
By Setter https://www.javaguides.net/2018/06/spring-dependency-injection-via-setter.html
By Constructor https://www.javaguides.net/2018/06/spring-dependency-injection-via.html
Annotations
@ConditionalOnClass @ConditionaOnMissingBean