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
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
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
Explanation: 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
View Answer
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
Explanation: 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
View Answer
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
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.
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
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
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.
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
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
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
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
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
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
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.
- Get Free Certificate of Merit in Spring
- Participate in Spring Certification Contest
- Become a Top Ranker in Spring
- Take Spring Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Programming Internship
- Practice Programming MCQs
- Buy Information Technology Books
- Buy Spring Books
- Apply for Spring Internship