Spring Questions and Answers – Spring Dynamic Modules

This set of tricky Java Spring questions and answers focuses on “Spring Dynamic Modules”.

1. To create services and have those automatically installed in the registry.
a) Spring Dynamic Modules
b) Spring DM Server
c) Spring Tooling
d) None of the mentioned
View Answer

Answer: a
Explanation: You can use Spring Dynamic Modules configuration schema to export a service. The service will be made available to other beans as well as other OSGi components.

2. Element to export the bean as an OSGi service, classified by the interface we specify.
a) osgix
b) osgi:service
c) all of the mentioned
d) none of the mentioned
View Answer

Answer: b
Explanation: We’ll use the osgi:service element to export the bean as an OSGi service, classified by the interface we specify.

3. These beans are proxies, some may load asynchronously or take a longer time to register.

advertisement
advertisement
<osgi:service
      interface="com.apress.springrecipes.
      osgi.helloworld.service.GreeterService">
      <bean class="com.apress.springrecipes.osgi.helloworld.
      service.GreeterServiceImpl"/>
</osgi:service>

a) True
b) False
View Answer

Answer: a
Explanation: This implies that you may have timing issues to resolve in configuring your service. For this, Spring Dynamic Modules provides the depends-on attribute, which lets your bean wait for another bean.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

4. An anonymous bean specified inside of the osgi:service element allows you to avoid cluttering the namespace.
a) True
b) False
View Answer

Answer: a
Explanation: You can abbreviate the syntax by using an anonymous bean.

<osgi:service auto-export="all-classes" ref="greeterService">
<osgi:interfaces>
<value>com.apress.springrecipes.osgi.helloworld.service.GreeterService</value>
<value>com.apress.springrecipes.osgi.helloworld.service.GreetingRecorderService</value>
</osgi:interfaces>
</osgi:service>

5. The first, most direct connection to OSGi is the bean that’s created on your behalf when you export a service. This bean, an instance of:-
a) org.osgi.framework.ServiceRegistration
b) org.osgi.framework.Service
c) org.osgi.framework.ServiceRegister
d) none of the mentioned
View Answer

Answer: a
Explanation: This bean, an instance of org.osgi.framework.ServiceRegistration, is in turn a delegate to the Spring bean you have defined.
advertisement

6. By default, beans created in a Spring application context are global to the entire OSGi runtime.
a) True
b) False
View Answer

Answer: a
Explanation: By default, beans created in a Spring application context are global to the entire OSGi runtime, including all clients that use it.
advertisement

7. Sometimes, you may want to limit the visibility of a service so that multiple clients each get their own instance of the bean.
a) time
b) scope
c) attr
d) none of the mentioned
View Answer

Answer: b
Explanation: Spring Dynamic Modules provides a clever use of the scope attribute here, allowing you to limit beans exported as services to the client, or service importer.

8. Spring Dynamic Modules also supports injection and manipulation of bundles themselves. An injected bundle is of type:-
a) org.osgi.framework.savedBundle
b) org.osgi.framework.Bundle
c) org.osgi.framework.BundleInstance
d) none of the mentioned
View Answer

Answer: b
Explanation: The simplest use case is that you want to obtain an instance of the org.osgi.framework.Bundle class from an already loaded bundle in the system.

9. Once acquired, the Bundle can be interrogated to introspect information about the bundle itself, including any entries, its current state.
a) True
b) False
View Answer

Answer: a
Explanation: Once acquired, the Bundle can be interrogated to introspect information about the bundle itself, including any entries, its current state (which can be any of: UNINSTALLED, INSTALLED, RESOLVED, STARTING, STOPPING, or ACTIVE), and any headers specified on the bundle.

10. OSGi will let you maintain multiple versions of a service in your registry at the same time.
a) True
b) False
View Answer

Answer: a
Explanation: OSGi, and Spring Dynamic Modules on top of it, provides many tools for discriminating services both in publishing and consuming services.

11. Multiple services of the same interface may be registered inside of an OSGi environment, which necessitates a conflict-resolution process.
a) True
b) False
View Answer

Answer: a
Explanation: To aid in that, Spring Dynamic Modules provides a few features to help.

12. When specified on a service element, allows the ascription of a rank relative to other beans with the same interface.
a) Ranking
b) Service
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: a
Explanation: Ranking is specified on the service element itself. When encountered, the OSGi runtime will return the service with the highest-ranking integer value.

13. A more robust solution to service discrimination is service attributes.
a) True
b) False
View Answer

Answer: a
Explanation: A service attribute is an arbitrary key and value pair that the service exports, and on which lookups for a service with multiple matches can be predicated.

14. There are frequently situations where OSGi will return more than one instance of a service that satisfies the interface.
a) True
b) False
View Answer

Answer: a
Explanation: Take, for example, a deployment where you have multiple GreeterServices deployed for various regions. Spring Dynamic Modules provides the set and list interfaces to retrieve multiple references and populate a java.util.Set and java.util.List, respectively.

15. Attribute, which, is the symbolic name of another bundle.
a) Fragment
b) Fragment-Host
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: b
Explanation: The Fragment-Host attribute, in turn, is the symbolic name of another bundle.

Sanfoundry Global Education & Learning Series – Java Spring.
To practice tricky questions and answers on 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.