Spring Core and Context Flashcards
Concepts of Spring DI framework
Which interface is used to create spring IOC container?
ApplicationContext. There are multiple implementations of ApplicationContext. One needs to choose based on their requirement.
Which are common implementations of ApplicationContext
ClasspathXMLApplicationContext, FileSystemXmlApplicationContext, AnnoationConfigApplicationContext, XmlWebApplicationContext, AnnotationConfigWebApplicationContext.
What are POJO objects called in Spring?
Beans
Which are mandatory properties for defining a bean in spring xml?
Bean id or name, bean class are mandatory properties.
Which xml tag is used to inject a dependency in spring bean?
is used to inject a bean.
Which xml tag is used to inject dependency using constructor?
tag is used.
What happens if there are two beans of same type and a class wants an instance of that bean?
Then spring will fail as it will get confused as to which bean needs to be injected. Then we need @Qualifier annotation.
Which xml configuration needs to be enabled to start autowiring using annotation?
enables autowiring using annotation.
@Autowired, @PostConstruct, @PreDestroy,
@PersistanceContext (if avaiable, like hibernate), @PersistanceUnit (if available)
Which ways are used to do some post processing once all dependencies have been injected?
@PostConstruct annotation or using InitializingBean interface or init-method property of tag in xml.
Which ways are used to do some pre processing before the context is destroyed and bean is destroyed?
@PreDestroy annotation, DisposableBean interface or destroy-method property of tag in xml.
When is pre destroy call made?
When the application context is closed.
How many types of autowiring is supported?
ByType, ByName or Constructor
Which is default autowiring type?
Default mode in java based autowiring is byType.
Which is the super class of Spring ApplicationContext?
BeanFactory is super of ApplicationContext.
What additional features of ApplicationContext?
It adds enterprise level features like Internationalization, etc.
Which is default autowiring type?
Default mode in java based autowiring is byType.
Which is the super class of Spring ApplicationContext?
BeanFactory is super of ApplicationContext
What additional features of ApplicationContext?
It adds enterprise level features like Internationalization, etc.
Lifecycle of Spring Bean
1) Initialize Bean
2) Set dependencies
3) Set Bean factory or ApplicationContext
4) Init method or Post Construct method
5) Bean is used in application
6) Container is destroyed
7) Pre Destroyed method is called
In what order will pre destory method of beans be called?
TBA
How to pass hard coded value in bean property?
How to get bean from ApplicationContext?
ApplicationContext applicatioContext = new ClasspathXmlApplicationContext(""); Type type = (Type) applicationContext.getBean("byName"); Type bean = applicationContext.getBean("byName", Type.class);
Inner bean
Useful if some bean creation should not be allowed from outside directly. It only should be created inside other bean.
…
Now if you try to create hostel bean from outside you will not be able to create it.
Alias for a bean