Java Spring Multiple Choice Questions & Answers (MCQs) on “Bean Post Processors”.
1. Method used to process bean before initialization callback
a) scope
b) postProcessAfterInitialization()
c) postProcessBeforeInitialization()
d) it’s own constructor
Answer: c
Clarification: You can process every bean before initialization callback method by implementing the postProcessBeforeInitialization() and methods.
2. Method used to process bean after initialization callback
a) scope
b) getBean
c) postProcessAfterInitialization()
d) it’s own constructor
Answer: c
Clarification: You can process every bean after initialization callback method by implementing the postProcessAfterInitialization() and methods.
3. Which method is used to gracefully shutdown all the bean processes after closing the spring container?
a) shutdownHook
b) destroy method
c) none of the mentioned
d) all of the mentioned
Answer: a
Clarification: ShutdownHook method gracefully shuts down each bean process before closing the container.
4. Which method is used to register BeanPostProcessor?
a) addBeanPostProcessors
b) registerBeanPostProcessors
c) addBeanProcessors
d) none of the mentioned
Answer: a
Clarification: When using a bean factory as your IoC container, bean post processors can only be registered programmatically, or more accurately, via the addBeanPostProcessor() method.
5. In application context, BeanPost Processors are registered using addBeanPostProcessors method
a) True
b) False
Answer: b
Clarification: Using an application context, the registration will be as simple as declaring an instance of the processor in the bean configuration file.
6. Which Interface for bean Post Processor is used to distinguish between checked beans
a) StorageConfig
b) Marker
c) None of the mentioned
d) All of the mentioned
Answer: a
Clarification: First of all, for the bean post processor to distinguish which beans should be checked, you create a marker interface, StorageConfig, for your target beans to implement.
7. Which method of bean post processors is used to check path existence
a) getPath
b) setPath
c) value
d) auto-wiring
Answer: a
Clarification: Moreover, for your bean post processor to check for path existence, it must be able to access the path property. This can be done by adding the getPath() method to this interface.
8. It’s possible to replace the original bean instance with a brand-new instance in your bean post processor
a) True
b) False
Answer: a
Clarification: Both the postProcessBeforeInitialization() and postProcessAfterInitialization() methods must return an instance for the bean being processed.
9. PathCheckingBeanPostProcessor will not work properly in case of:-
a) XML Configuration
b) Java based Configuration
c) JSR Annotation
d) None of the mentioned
Answer: c
Clarification: This is because your bean post processor has a lower priority than CommonAnnotationBeanPostProcessor by default. As a result, the initialization method will be called before your path checking.
10. Which bean factory post processor externalizes part of the bean configurations into a properties file
a) PropertyPlaceholderConfigurer
b) PropertyPlaceholderRegister
c) PropertyGetPath
d) None of the mentioned
Answer: a
Clarification: Spring comes with a bean factory post processor called PropertyPlaceholderConfigurer for you to externalize part of the bean configurations into a properties file.
11. Which interface defines methods for resolving text messages
a) MessageSource
b) ApplicationListener
c) ApplicationContextListener
d) TextEvent
