Spring Questions and Answers – Bean Post Processors

This set of Java Spring Multiple Choice Questions & Answers (MCQs) focuses on “Bean Post Processors”.

1. Method used to process bean before initialization callback
a) scope
b) postProcessAfterInitialization()
c) postProcessBeforeInitialization()
d) it’s own constructor
View Answer

Answer: c
Explanation: 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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: a
Explanation: ShutdownHook method gracefully shuts down each bean process before closing the container.
advertisement
advertisement

4. Which method is used to register BeanPostProcessor?
a) addBeanPostProcessors
b) registerBeanPostProcessors
c) addBeanProcessors
d) none of the mentioned
View Answer

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: Using an application context, the registration will be as simple as declaring an instance of the processor in the bean configuration file.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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.
advertisement

8. It’s possible to replace the original bean instance with a brand-new instance in your bean post processor
a) True
b) False
View Answer

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: 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.
advertisement

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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: MessageSource is an interface that defines several methods for resolving messages.

12. Which interface is used to listen to certain events
a) ApplicationListener
b) ContextListener
c) EventListener
d) None of the mentioned
View Answer

Answer: a
Explanation: For a bean to listen to certain events, it must implement the ApplicationListener interface and handle the events in the onApplicationEvent() method.

13. Which method is used to publish your own custom event
a) contextPublish
b) publishEvent
c) applicationEventPublish
d) addEvent
View Answer

Answer: b
Explanation: Any bean can publish an event by calling an application event publisher’s publishEvent() method.

14. Which of the following is a well known recognized event
a) ContextCloasedEvemt
b) ContextRefreshedEvent
c) RequestHandledEvent
d) All of the mentioned
View Answer

Answer: d
Explanation: The application context itself will also publish container events such as ContextClosedEvent, ContextRefreshedEvent, and RequestHandledEvent.

15. Which event is provoked when web request comes into action
a) ContextClosedEvent
b) ContextStoppedEvent
c) SessionEvent
d) RequestHandledEvent
View Answer

Answer: d
Explanation: Web request events are handled by RequestHandledEvent.

Sanfoundry Global Education & Learning Series – Java Spring.
To practice all areas of Java Spring, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.