Spring annotations and Basics
- @component - is the most generic one and @repository, @ service, @controller are supposed to be used in their specific layers
- @repository - So when you tag any component with at repository, spring would automatically add the exception translation for Jdbc exceptions.So whenever a Jdbc exception happens, then it needs to be translated into the specific spring exception.
- spring beans are not thread safe
- scope: singleton(default scope), prototype, request and session.
- request and session are both applicable only in web application context.
- gang of four singleton or basic singleton: it means one instance per class loader.
- The spring singleton is one instance per container, one instance per application context. if you multiple application context than you will have multiple objects
- Constructor injection: to create immutable beans and for mandatory dependencies
- Setter injection: Ex: internationalize something, which are not required while creating and setter injection for optional dependencies.
- @Autowire: if only one implementation than by type. otherwise by name of the variable
- NosuchBeanException: bean not scaned means
- NouniqueBeanDefination: if multiple implementation per interface and variable name is interface name
- @Autowire
- ClassA classAImpl;
- Search by type ClassA if multiple bean on same type , match by variable name "classAImpl" , if no match found then by name used @primary or match by qulifier
- @primary : on class to tell use this implementation class for injection to solve NOsuchBeanException
- @qulifier("") : used on class ann injection to identify bean
- BOM - bill of materials dependency to have same spring versions. all versions will take from dependency Management
No comments:
Post a Comment