Re: How do You use spring in OSGi?
For sure I will evaluate it and I let You know. It seems that mixture of blueprint and spring to connect beans from different bundle is the only option. Nobody has tried to connect bean factories from different bundles to produce beans graph as we did to have more transparent solution Regards Tomek -- View this message in context: http://karaf.922171.n3.nabble.com/How-do-You-use-spring-in-OSGi-tp4046335p4046374.html Sent from the Karaf - User mailing list archive at Nabble.com.
Re: How do You use spring in OSGi?
If you have failing use cases, please raise a JIRA issue with a reproducible test case so that I can have a look. 2016-04-25 23:01 GMT+02:00 Tomek: > Hi Guillaume > So we have solution for spring namespaces but what with class loaders in > spring, is it solved also by blueprint-spring-extender? part of spring > code > is using ClassUtil which returns ContextClassLoader > > Regards > Tomasz > > > > > -- > View this message in context: > http://karaf.922171.n3.nabble.com/How-do-You-use-spring-in-OSGi-tp4046335p4046359.html > Sent from the Karaf - User mailing list archive at Nabble.com. > -- Guillaume Nodet Red Hat, Open Source Integration Email: gno...@redhat.com Web: http://fusesource.com Blog: http://gnodet.blogspot.com/
Re: How do You use spring in OSGi?
Hi Guillaume So we have solution for spring namespaces but what with class loaders in spring, is it solved also by blueprint-spring-extender? part of spring code is using ClassUtil which returns ContextClassLoader Regards Tomasz -- View this message in context: http://karaf.922171.n3.nabble.com/How-do-You-use-spring-in-OSGi-tp4046335p4046359.html Sent from the Karaf - User mailing list archive at Nabble.com.
Re: How do You use spring in OSGi?
Hi Guillaume, do you have some documentation for the blueprint-spring/blueprint-spring-extender usage? Does it use the blueprint service/reference declarations for OSGi integration? The Aries frontpage seems quite outdated ... Thanks and Best Regards, Michael 2016-04-24 23:15 GMT+02:00 Guillaume Nodet: > You can use the blueprint-spring namespace handler and > blueprint-spring-extender bundle. > The first one provides full support for spring namespaces (including > custom ones) from a blueprint app. So you can simply have an empty > blueprint which import the spring xml. > > The second one is an equivalent of spring-osgi / spring-dm. The exact > same namespace is supported, but on top of the above. > > Those bundles have been released at Aries in version 0.2.0 very recently. > Feel free to have a look and see if they help. > > > 2016-04-23 10:42 GMT+02:00 Tomek : > >> Christian and Tom >> >> Thanks for Your answer, so I see now that spring in OSGi is problematic in >> general it is not only our case. >> >> Unfortunately Blueprint or DS is not an option for us because there is no >> agreement in the team to use something else than spring (it is a strong >> resistance) so we stay with our library for spring on osgi for long. >> But Christian Your plugin is also a nice solution as it reduce the work >> related to maintaining blueprint.xml , I didn't spotted it earlier >> >> Thanks >> Tomasz >> >> >> >> -- >> View this message in context: >> http://karaf.922171.n3.nabble.com/How-do-You-use-spring-in-OSGi-tp4046335p4046338.html >> Sent from the Karaf - User mailing list archive at Nabble.com. >> > > > > -- > > Guillaume Nodet > > Red Hat, Open Source Integration > > Email: gno...@redhat.com > Web: http://fusesource.com > Blog: http://gnodet.blogspot.com/ > >
Re: How do You use spring in OSGi?
You can use the blueprint-spring namespace handler and blueprint-spring-extender bundle. The first one provides full support for spring namespaces (including custom ones) from a blueprint app. So you can simply have an empty blueprint which import the spring xml. The second one is an equivalent of spring-osgi / spring-dm. The exact same namespace is supported, but on top of the above. Those bundles have been released at Aries in version 0.2.0 very recently. Feel free to have a look and see if they help. 2016-04-23 10:42 GMT+02:00 Tomek: > Christian and Tom > > Thanks for Your answer, so I see now that spring in OSGi is problematic in > general it is not only our case. > > Unfortunately Blueprint or DS is not an option for us because there is no > agreement in the team to use something else than spring (it is a strong > resistance) so we stay with our library for spring on osgi for long. > But Christian Your plugin is also a nice solution as it reduce the work > related to maintaining blueprint.xml , I didn't spotted it earlier > > Thanks > Tomasz > > > > -- > View this message in context: > http://karaf.922171.n3.nabble.com/How-do-You-use-spring-in-OSGi-tp4046335p4046338.html > Sent from the Karaf - User mailing list archive at Nabble.com. > -- Guillaume Nodet Red Hat, Open Source Integration Email: gno...@redhat.com Web: http://fusesource.com Blog: http://gnodet.blogspot.com/
Re: How do You use spring in OSGi?
Christian and Tom Thanks for Your answer, so I see now that spring in OSGi is problematic in general it is not only our case. Unfortunately Blueprint or DS is not an option for us because there is no agreement in the team to use something else than spring (it is a strong resistance) so we stay with our library for spring on osgi for long. But Christian Your plugin is also a nice solution as it reduce the work related to maintaining blueprint.xml , I didn't spotted it earlier Thanks Tomasz -- View this message in context: http://karaf.922171.n3.nabble.com/How-do-You-use-spring-in-OSGi-tp4046335p4046338.html Sent from the Karaf - User mailing list archive at Nabble.com.
Re: How do You use spring in OSGi?
I also had the duty to help migrate a spring application to OSGi some time ago. My approach was to use standard based annotations as far as possible and make sure spring as well as blueprint can make use of them. The result was the Aries blueprint-maven-plugin. It parses a subset of CDI and JEE annotations and creates blueprint xml files at build time. As the same standard annotations also work in spring the code then still works on the spring side. See http://aries.apache.org/modules/blueprint-maven-plugin.html At the start of the migration we simply did not use OSGi services and instead used a similar approach to spring to wire the beans. We extended the scan paths to packages from bundles we depend on. So the result was a blueprint that looked like the combined spring contexts. The next step was to use real OSGi services in OSGi while still wiring beans outside OSGi. We used the @OsgiServiceProvider annoations on the beans to become services. Outside OSGi these were them simply ignored. In the client side you normally use @OSgiService @Inject at each point where you need the service. This will not work outside OSGi though as with CDI rules it would expect the bean to inject to also have the OsgiService annotation. So we found a little trick on each client object we simply use @Inject which means a normal bean inject in blueprint. Then we created one extra empty class per bundle with just the @OsgiService @Inject myService for each service. This triggers the plugin to create the service reference elements in blueprint. So we ended up with jars that were valid spring jars and OSGi bundles. Over time when you gain confidence in OSGi you can then remove the spring xmls to have pure OSGi bundles. Christian 2016-04-22 16:21 GMT+02:00 Tom Barber: > Hey Tomasz > > As opposed to answering the question at the end of your email, I'll answer > your subject, which are subtly different ;) > > I migrated a bunch of webapp stuff to Karaf and I spent ages trying to > figure out the spring stuff, then I suddenly realised. don't use it! :) > > If I chat to people migrating webapps these days I try and steer them away > from Spring, don't get me wrong in a non OSGI environment I use spring all > the time, but in OSGI CDI and Blueprint have been more than enough for me > and the projects I've worked on. > > Especially since Spring stopped support for OSGI stuff it seems to me to > be getting progressively worse, so my own opinion is even if in the short > term there is a gain with the synergy and cross over between 2 apps, at the > end of the day it mostly provides wiring, which you can get better support > for out of Blueprint. > > My 2 cents. > > Tom > > On Fri, Apr 22, 2016 at 2:56 PM, Tomasz Wozniak < > tomasz.wozn...@s3group.com> wrote: > >> Hi >> >> We've selected OSGi to modularize our system, it is obvious. Our >> technological background is JEE with spring framework. As we were >> satisfied with spring, JEE servers are hard to reconfigure, so we took on >> the table Karaf and we felt some confusion related to programing model. On >> the forum there were some discussions which recommended Spring DM or >> Blueprint but karaf provides also spring framework bundles which dosen’t >> work in OSGi out of the box in our opinion. We met two major problems: >> >> 1.ClassLoaders, You can set up class loader for spring >> application context, but some classes in spring uses >> org.springframework.util.ClassUtil which return ContextClassLoader and >> every method is static so there is no option to override it >> >> 2.We weren’t able to load spring schema definitions from >> spring bundles (eg. tx, mvc, context) >> >> >> >> So the question is if there is some OSGi library which solves those >> problems or the only option is to use blueprint? >> >> >> >> Moreover OSGi is a novelty for us and we would like to have a cheap >> fallback solution to technology which we know -> spring + JEE servers, we >> decided to write own library which will allows us to use newest spring >> version in OSGi in a transparent manner. >> >> I would like to share idea behind that library to get opinions from more >> advanced OSGi users, maybe there is a similar solution on the market which >> we’ve missed. >> >> >> >> We looked at Spring DM, Blueprint and Peaberry they are designed around >> the same idea -> OSGi services are connected based on the information given >> in the annotations and this approach ties code to OSGi environment. We >> decided to operate on connected ServiceFactories which produces for user >> required service graph, such approach removes from code OSGi specific >> annotations actually we have two layers, ServiceFactory layer which know >> that operate in OSGi environment, and service layer which is OSGi free. >> >> >> >> In Spring ServiceFactory it is a Bean Factory or Application Context >> which extends Bean Factory so we are putting them to OSGi servise
Re: How do You use spring in OSGi?
Hey Tomasz As opposed to answering the question at the end of your email, I'll answer your subject, which are subtly different ;) I migrated a bunch of webapp stuff to Karaf and I spent ages trying to figure out the spring stuff, then I suddenly realised. don't use it! :) If I chat to people migrating webapps these days I try and steer them away from Spring, don't get me wrong in a non OSGI environment I use spring all the time, but in OSGI CDI and Blueprint have been more than enough for me and the projects I've worked on. Especially since Spring stopped support for OSGI stuff it seems to me to be getting progressively worse, so my own opinion is even if in the short term there is a gain with the synergy and cross over between 2 apps, at the end of the day it mostly provides wiring, which you can get better support for out of Blueprint. My 2 cents. Tom On Fri, Apr 22, 2016 at 2:56 PM, Tomasz Wozniakwrote: > Hi > > We've selected OSGi to modularize our system, it is obvious. Our > technological background is JEE with spring framework. As we were > satisfied with spring, JEE servers are hard to reconfigure, so we took on > the table Karaf and we felt some confusion related to programing model. On > the forum there were some discussions which recommended Spring DM or > Blueprint but karaf provides also spring framework bundles which dosen’t > work in OSGi out of the box in our opinion. We met two major problems: > > 1.ClassLoaders, You can set up class loader for spring > application context, but some classes in spring uses > org.springframework.util.ClassUtil which return ContextClassLoader and > every method is static so there is no option to override it > > 2.We weren’t able to load spring schema definitions from > spring bundles (eg. tx, mvc, context) > > > > So the question is if there is some OSGi library which solves those > problems or the only option is to use blueprint? > > > > Moreover OSGi is a novelty for us and we would like to have a cheap > fallback solution to technology which we know -> spring + JEE servers, we > decided to write own library which will allows us to use newest spring > version in OSGi in a transparent manner. > > I would like to share idea behind that library to get opinions from more > advanced OSGi users, maybe there is a similar solution on the market which > we’ve missed. > > > > We looked at Spring DM, Blueprint and Peaberry they are designed around > the same idea -> OSGi services are connected based on the information given > in the annotations and this approach ties code to OSGi environment. We > decided to operate on connected ServiceFactories which produces for user > required service graph, such approach removes from code OSGi specific > annotations actually we have two layers, ServiceFactory layer which know > that operate in OSGi environment, and service layer which is OSGi free. > > > > In Spring ServiceFactory it is a Bean Factory or Application Context which > extends Bean Factory so we are putting them to OSGi servise registry. > Spring Application Contexts are connected by ParentBeanFactory which > searches in OSGi service registry for required Spring Application Contexts > by given bundle base on some additional OSGi headers. Which such > configuration bundle application context produces spring beans/services for > implementation which comes from that bundle or delegates creation to wired > Spring Application Contexts by parent bean factory. > > > > > > Maybe in point how it works: > > 1.Each bundle with implementation has its own Spring Context > published in OSGi service registry > > 2.Spring context are wired via parent bean factory, for that > purpose we introduced two types of bundles, > > a.one which contains beans interfaces called API bundle > > b.second type which contains implementation and thus > containing spring context, that bundle is saying in OSGi headers which API > is implementing and which API is using. Based on that information Spring > bean factories are connected in dependency graph on the factory level > > 3.Recommended scope for spring beans is session, request or > prototype thanks to that we can have hot deployment for implementation. We > can install new implementation bundle and its bean factory will be used by > new user sessions, old user sessions will be using previously installed > implementation. With singleton scope we are unable to use newly uploaded > implementation as singleton beans are wired during first request. > > 4.Ongoing user session is unchanged by deployment of new > implementation bundle, it uses the old one. It was important for us as we > developing medical device and such change during user session can be > unpredictable > > > > > > How it is implemented > > 1.Library provides SpringActivator which starts spring > application contexts and configure for