Is it possible to automatically register a Spring @Component
(or one of its specifications; e.g. @Repository
) as an OSGi service? So I can use autowiring and all other benefits of Spring inside one bundle and OSGi Service Registry to communicate between bundles?
UPDATE: From this discussion it doesn't seem to be possible using standard Blueprint, only in Eclipse Gemini.
Spring DM is composed of a set of OSGi bundles that become part of the infrastructure when installed in an OSGi container. They can then manage a Spring application context for bundles or even start a web container inside the OSGi container.
The OSGi Service Platform provides a mechanism for developing applications by using a component model and deploying those applications into an OSGi framework. The OSGi architecture is separated into a number of layers that provide benefits to creating and managing Java™ applications.
The Open Service Gateway Initiative is a specification defining a Java-based component system. It's currently managed by the OSGi Alliance, and its first version dates back to 1999. Since then, it has proved to be a great standard for component systems, and it's widely used nowadays.
OSGI is an application architecture, while microservices is a distributed systems concept. In my experience, microservices offer a number of benefits: Individual microservices are easy to deploy, test, and maintain. Microservices are language agnostic.
I assume you're familiar with Eclipse Gemini Blueprint (formerly Spring Dynamic Modules, formerly Spring OSGi)?
You export your beans using the <service>
-tag. I'm not sure if you can export all @Component
etc. annotated beans automatically though.
A possible implementation to support this without the hack @AlexeyRomanov suggested could be to add a BeanFactoryPostProcessor
implementation to the extender bundle of Gemini Blueprint via a fragment.
That processor than could create the needed OSGi export definitions inside the BeanFactory and it should work properly.
An example of how that could look like is the ServiceReferenceInjectionBeanPostProcessor
form SpringDM's/Gemini's extension that allows you to get OSGi-Services injected via the @ServiceReference
annotation. (Although I linked Spring DM this class should still be present in Gemini, but I couldn't find a direct link to their javadoc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With