I'm just wondering, are there any publicly available examples of OSGi-fied Spring MVC web app., and especially with detailed instructions on how to integrate and deploy OSGi runtime to Tomcat?
Is it even possible today to have typical Spring MVC apps (with DispatcherServlet and all that) to be deployed in Tomcat and have shared OSGi services running and shared amongst them, without any trickery like Equinox HttpServletBridge, etc.
I'm new to OSGi, so please don't judge my question too much :-)
> I'm just wondering, are there any publicly available examples of OSGi-fied > Spring MVC web app., and especially with detailed instructions on how to > integrate and deploy OSGi runtime to Tomcat?
> Is it even possible today to have typical Spring MVC apps (with > DispatcherServlet and all that) to be deployed in Tomcat and have shared > OSGi services running and shared amongst them, without any trickery like > Equinox HttpServletBridge, etc.
> I'm new to OSGi, so please don't judge my question too much :-)
if you don't what to use the servlet bridge you should think about running your container inside OSGi instead of the standard tomcat. Then you use the OSGi runtime as underlying technology and deploy your servlet container (for example) as OSGi bundle, as well as your apps and services. In this setting you can easily share services and bundles across different web apps.
As far as I know you can use Jetty as OSGi bundle right out of the box. Letting tomcat run within an OSGi bundle might be more complicated but it possible as well, I think.
> I'm just wondering, are there any publicly available examples of OSGi-fied > Spring MVC web app., and especially with detailed instructions on how to > integrate and deploy OSGi runtime to Tomcat?
> Is it even possible today to have typical Spring MVC apps (with > DispatcherServlet and all that) to be deployed in Tomcat and have shared > OSGi services running and shared amongst them, without any trickery like > Equinox HttpServletBridge, etc.
> I'm new to OSGi, so please don't judge my question too much :-)
> if you don't what to use the servlet bridge you should think about > running your container inside OSGi instead of the standard tomcat. Then > you use the OSGi runtime as underlying technology and deploy your > servlet container (for example) as OSGi bundle, as well as your apps and > services. In this setting you can easily share services and bundles > across different web apps.
> As far as I know you can use Jetty as OSGi bundle right out of the box. > Letting tomcat run within an OSGi bundle might be more complicated but > it possible as well, I think.
> HTH,
> Martin
> Dmitriy Kopylenko wrote: > > Hello gang.
> > I'm just wondering, are there any publicly available examples of > OSGi-fied > > Spring MVC web app., and especially with detailed instructions on how to > > integrate and deploy OSGi runtime to Tomcat?
> > Is it even possible today to have typical Spring MVC apps (with > > DispatcherServlet and all that) to be deployed in Tomcat and have shared > > OSGi services running and shared amongst them, without any trickery like > > Equinox HttpServletBridge, etc.
> > I'm new to OSGi, so please don't judge my question too much :-)
> > I'm just wondering, are there any publicly available examples of > > OSGi-fied Spring MVC web app., and especially with detailed instructions on > > how to integrate and deploy OSGi runtime to Tomcat?
> > Is it even possible today to have typical Spring MVC apps (with > > DispatcherServlet and all that) to be deployed in Tomcat and have shared > > OSGi services running and shared amongst them, without any trickery like > > Equinox HttpServletBridge, etc.
> > I'm new to OSGi, so please don't judge my question too much :-)
Is there any hope of getting Bernd Kolb's utilities to run on Spring
DM 1.0.1? The reason I ask is that I have already tried and get into
problems with a null bundle in OsgiBundleResource.<init>. I had to
comment out a call to LocalBundleContext.setContext in his
BundleContextLoader, since that method is no longer accessible in more
recent versions of Spring DM. It might very well be caused by that,
but I can't say for sure.
Would it be better to try out the upcoming web support in Spring DM?
It seems to be in SVN, but I don't know if it's usable at this stage.
--
Ulrik
Here is the stack trace:
java.lang.IllegalArgumentException: Bundle must not be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at
org.springframework.osgi.io.OsgiBundleResource.<init>(OsgiBundleResource.ja va:
118)
at
org.springframework.osgi.io.OsgiBundleResourcePatternResolver.getResources( OsgiBundleResourcePatternResolver.java:
102)
at
org.springframework.context.support.AbstractApplicationContext.getResources (AbstractApplicationContext.java:
1019)
at
org.springframework.beans.factory.support.AbstractBeanDefinitionReader.load BeanDefinitions(AbstractBeanDefinitionReader.java:
177)
at
org.springframework.beans.factory.support.AbstractBeanDefinitionReader.load BeanDefinitions(AbstractBeanDefinitionReader.java:
149)
at
org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDe finitions(XmlWebApplicationContext.java:
124)
at
org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDe finitions(XmlWebApplicationContext.java:
92)
at
org.springframework.context.support.AbstractRefreshableApplicationContext.r efreshBeanFactory(AbstractRefreshableApplicationContext.java:
123)
at
org.springframework.context.support.AbstractApplicationContext.obtainFreshB eanFactory(AbstractApplicationContext.java:
423)
at
org.springframework.context.support.AbstractApplicationContext.refresh(Abst ractApplicationContext.java:
353)
at
org.example.util.spring.osgi.context.OSGiDispatcherServlet.createWebApplica tionContext(OSGiDispatcherServlet.java:
65)
at
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext( FrameworkServlet.java:
292)
at
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkS ervlet.java:
262)
at
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:
126)
at javax.servlet.GenericServlet.init(GenericServlet.java:241)
at
org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:
433)
... 35 more
Here is the commented line:
...
import
org.springframework.osgi.service.importer.support.LocalBundleContext;
...
/**
* A {@link ContextLoader} which creates a {@link
OSGiGenericApplicationContext} for
* the given {@link BundleContext}
*
* @author Bernd Kolb
*
*/
public class BundleContextLoader extends ContextLoader {
...
protected WebApplicationContext createWebApplicationContext(
ServletContext servletContext, ApplicationContext parent)
throws BeansException {
ClassLoader contextClassLoader = Thread.currentThread()
.getContextClassLoader();
try {
ClassLoader cl = BundleDelegatingClassLoader
.createBundleClassLoaderFor(ctx.getBundle(), getClass()
.getClassLoader());
Thread.currentThread().setContextClassLoader(cl);
//LocalBundleContext.setContext(ctx);
OSGiGenericApplicationContext appContext = new
OSGiGenericApplicationContext(ctx, parent, servletContext);
appContext.refresh();
return appContext;
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
On 15 Feb, 14:45, "Gerd Wütherich" <g...@gerd-wuetherich.de> wrote:
> > I'm just wondering, are there any publicly available examples of OSGi-fied
> > Spring MVC web app., and especially with detailed instructions on how to
> > integrate and deploy OSGi runtime to Tomcat?
> > Is it even possible today to have typical Spring MVC apps (with
> > DispatcherServlet and all that) to be deployed in Tomcat and have shared
> > OSGi services running and shared amongst them, without any trickery like
> > Equinox HttpServletBridge, etc.
> > I'm new to OSGi, so please don't judge my question too much :-)
As they run under osgi you can use in your war manifest all the normal osgi headers so you can import the required packages and you then do not need to have your classes available in WEB-INF/classes or in a jar n WEB-INF/lib. If you need access to service registry to get services from another bundle you just have to implement a bundle activator and specify the activator in war manifest as for any other bundle. The trick is how you pass the bundle context to your servlets/filters/listeners or anything that needs it, but it shouldn't be to hard as a simple singleton may do the trick. If you find it just raise an issue on pax extender jira and I can publish the bundle context as a servlet context attribute or we can do the in the spring way by injecting into servlets/listeners/filters if they implement something like BundleContextAware.
But I guess the nicest part would be that the actual application context used by ServletDispatcher(FrameworkServlet) would be the application context created by Spring DM. I didn't had a deep look into it (nor I'm to much of an expert of Spring MVC) but It shouldn't be to hard to obtain that as I recall that FrameworkServlet supports some customization regarding the application context creation, so somehow it should be possible to make it use the app context created by spring extender. Is not on my priorities right now, so feel free to experiment ad let me know if you need some kind of support form pax web / pax web extender.
Ulrik, as you are now into this why not trying this?
On Fri, Feb 15, 2008 at 9:13 PM, Dmitriy Kopylenko <dima...@gmail.com> wrote: > Hello gang.
> I'm just wondering, are there any publicly available examples of OSGi-fied > Spring MVC web app., and especially with detailed instructions on how to > integrate and deploy OSGi runtime to Tomcat?
> Is it even possible today to have typical Spring MVC apps (with > DispatcherServlet and all that) to be deployed in Tomcat and have shared > OSGi services running and shared amongst them, without any trickery like > Equinox HttpServletBridge, etc.
> I'm new to OSGi, so please don't judge my question too much :-)
I'm currently trying to achieve the same thing here. I have pax-web
with a web application deployed and another bundle that exports an
OSGi service using Spring DM. I'm currently having trouble injecting
the service reference into a servlet filter due to the fact that I
cannot obtain a Context in the filter to perform the injection. Any
suggestions would be great.
Thanks,
Dave
On Mar 7, 10:19 pm, "Alin Dreghiciu" <adreghi...@gmail.com> wrote:
> As they run under osgi you can use in your war manifest all the normal
> osgi headers so you can import the required packages and you then do
> not need to have your classes available in WEB-INF/classes or in a jar
> n WEB-INF/lib. If you need access to service registry to get services
> from another bundle you just have to implement a bundle activator and
> specify the activator in war manifest as for any other bundle. The
> trick is how you pass the bundle context to your
> servlets/filters/listeners or anything that needs it, but it shouldn't
> be to hard as a simple singleton may do the trick. If you find it just
> raise an issue on pax extender jira and I can publish the bundle
> context as a servlet context attribute or we can do the in the spring
> way by injecting into servlets/listeners/filters if they implement
> something like BundleContextAware.
> But I guess the nicest part would be that the actual application
> context used by ServletDispatcher(FrameworkServlet) would be the
> application context created by Spring DM. I didn't had a deep look
> into it (nor I'm to much of an expert of Spring MVC) but It shouldn't
> be to hard to obtain that as I recall that FrameworkServlet supports
> some customization regarding the application context creation, so
> somehow it should be possible to make it use the app context created
> by spring extender.
> Is not on my priorities right now, so feel free to experiment ad let
> me know if you need some kind of support form pax web / pax web
> extender.
> Ulrik, as you are now into this why not trying this?
> Alin
> On Fri, Feb 15, 2008 at 9:13 PM, Dmitriy Kopylenko <dima...@gmail.com> wrote:
> > Hello gang.
> > I'm just wondering, are there any publicly available examples of OSGi-fied
> > Spring MVC web app., and especially with detailed instructions on how to
> > integrate and deploy OSGi runtime to Tomcat?
> > Is it even possible today to have typical Spring MVC apps (with
> > DispatcherServlet and all that) to be deployed in Tomcat and have shared
> > OSGi services running and shared amongst them, without any trickery like
> > Equinox HttpServletBridge, etc.
> > I'm new to OSGi, so please don't judge my question too much :-)
I have Spring MVC 2.5.3 working with Spring DM 2.0 M2. From what I can tell, Spring MVC's annotations are not supported by the Spring DM web bundle. Moving my controllers to having bean definitions in my *-servlet.xml solved the problem. Is this a missing feature of 2.0 M2?
On a related note, I was able to get things working with a JstlView, but not with FreeMarker. When I tried adding FreeMarker to the mix, the following error occurs. Note that my app works fine with "mvn jetty:run".
SEVERE: Servlet /myapp threw load() exception java.lang.NoClassDefFoundError: org/xml/sax/helpers/DefaultHandler at org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer.setSer vletContext(FreeMarkerConfigurer.java:101) at org.springframework.web.context.support.ServletContextAwareProcessor.postPr ocessBeforeInitialization(ServletContextAwareProcessor.java:75) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor y.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFa ctory.java:350) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor y.initializeBean(AbstractAutowireCapableBeanFactory.java:1329) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor y.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
I tried adding xercesImpl to my MANIFEST.MF (the version Spring uses to build with) but it didn't seem to help.
On Thu, Apr 17, 2008 at 4:58 AM, David Conde <i...@javadeveloper.eu> wrote:
> I'm currently trying to achieve the same thing here. I have pax-web > with a web application deployed and another bundle that exports an > OSGi service using Spring DM. I'm currently having trouble injecting > the service reference into a servlet filter due to the fact that I > cannot obtain a Context in the filter to perform the injection. Any > suggestions would be great.
> Thanks, > Dave
> On Mar 7, 10:19 pm, "Alin Dreghiciu" <adreghi...@gmail.com> wrote: > > Hi Dimitriy,
> > As they run under osgi you can use in your war manifest all the normal > > osgi headers so you can import the required packages and you then do > > not need to have your classes available in WEB-INF/classes or in a jar > > n WEB-INF/lib. If you need access to service registry to get services > > from another bundle you just have to implement a bundle activator and > > specify the activator in war manifest as for any other bundle. The > > trick is how you pass the bundle context to your > > servlets/filters/listeners or anything that needs it, but it shouldn't > > be to hard as a simple singleton may do the trick. If you find it just > > raise an issue on pax extender jira and I can publish the bundle > > context as a servlet context attribute or we can do the in the spring > > way by injecting into servlets/listeners/filters if they implement > > something like BundleContextAware.
> > But I guess the nicest part would be that the actual application > > context used by ServletDispatcher(FrameworkServlet) would be the > > application context created by Spring DM. I didn't had a deep look > > into it (nor I'm to much of an expert of Spring MVC) but It shouldn't > > be to hard to obtain that as I recall that FrameworkServlet supports > > some customization regarding the application context creation, so > > somehow it should be possible to make it use the app context created > > by spring extender. > > Is not on my priorities right now, so feel free to experiment ad let > > me know if you need some kind of support form pax web / pax web > > extender.
> > Ulrik, as you are now into this why not trying this?
> > Alin
> > On Fri, Feb 15, 2008 at 9:13 PM, Dmitriy Kopylenko <dima...@gmail.com> wrote: > > > Hello gang.
> > > I'm just wondering, are there any publicly available examples of OSGi-fied > > > Spring MVC web app., and especially with detailed instructions on how to > > > integrate and deploy OSGi runtime to Tomcat?
> > > Is it even possible today to have typical Spring MVC apps (with > > > DispatcherServlet and all that) to be deployed in Tomcat and have shared > > > OSGi services running and shared amongst them, without any trickery like > > > Equinox HttpServletBridge, etc.
> > > I'm new to OSGi, so please don't judge my question too much :-)
Matt Raible wrote: > I have Spring MVC 2.5.3 working with Spring DM 2.0 M2. From what I can > tell, Spring MVC's annotations are not supported by the Spring DM web > bundle. Moving my controllers to having bean definitions in my > *-servlet.xml solved the problem. Is this a missing feature of 2.0 M2?
No - component scanning (as well as classpath: and classpath*:) works however, due to a loading problem, meta-annotations are not discovered in an OSGI environment when using Spring 2.5.3. @Component works but @Controller does not. However, this is fixed in Spring HEAD (upcoming 2.5.4).
> On a related note, I was able to get things working with a JstlView, > but not with FreeMarker. When I tried adding FreeMarker to the mix, > the following error occurs. Note that my app works fine with "mvn jetty:run".
> SEVERE: Servlet /myapp threw load() exception > java.lang.NoClassDefFoundError: org/xml/sax/helpers/DefaultHandler > at org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer.setSer vletContext(FreeMarkerConfigurer.java:101) > at org.springframework.web.context.support.ServletContextAwareProcessor.postPr ocessBeforeInitialization(ServletContextAwareProcessor.java:75) > at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor y.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFa ctory.java:350) > at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor y.initializeBean(AbstractAutowireCapableBeanFactory.java:1329) > at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactor y.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
> I tried adding xercesImpl to my MANIFEST.MF (the version Spring uses > to build with) but it didn't seem to help.
> Any advice?
Haven't encountered this problem but you can just add an optional import (as Spring-DM does) and you should be set:
> On Thu, Apr 17, 2008 at 4:58 AM, David Conde <i...@javadeveloper.eu> wrote: >> I'm currently trying to achieve the same thing here. I have pax-web >> with a web application deployed and another bundle that exports an >> OSGi service using Spring DM. I'm currently having trouble injecting >> the service reference into a servlet filter due to the fact that I >> cannot obtain a Context in the filter to perform the injection. Any >> suggestions would be great.
>> Thanks, >> Dave
>> On Mar 7, 10:19 pm, "Alin Dreghiciu" <adreghi...@gmail.com> wrote: >>> Hi Dimitriy,
>>> As they run under osgi you can use in your war manifest all the normal >>> osgi headers so you can import the required packages and you then do >>> not need to have your classes available in WEB-INF/classes or in a jar >>> n WEB-INF/lib. If you need access to service registry to get services >>> from another bundle you just have to implement a bundle activator and >>> specify the activator in war manifest as for any other bundle. The >>> trick is how you pass the bundle context to your >>> servlets/filters/listeners or anything that needs it, but it shouldn't >>> be to hard as a simple singleton may do the trick. If you find it just >>> raise an issue on pax extender jira and I can publish the bundle >>> context as a servlet context attribute or we can do the in the spring >>> way by injecting into servlets/listeners/filters if they implement >>> something like BundleContextAware.
>>> But I guess the nicest part would be that the actual application >>> context used by ServletDispatcher(FrameworkServlet) would be the >>> application context created by Spring DM. I didn't had a deep look >>> into it (nor I'm to much of an expert of Spring MVC) but It shouldn't >>> be to hard to obtain that as I recall that FrameworkServlet supports >>> some customization regarding the application context creation, so >>> somehow it should be possible to make it use the app context created >>> by spring extender. >>> Is not on my priorities right now, so feel free to experiment ad let >>> me know if you need some kind of support form pax web / pax web >>> extender.
>>> Ulrik, as you are now into this why not trying this?
>>> Alin
>>> On Fri, Feb 15, 2008 at 9:13 PM, Dmitriy Kopylenko <dima...@gmail.com> wrote: >>>> Hello gang. >>>> I'm just wondering, are there any publicly available examples of OSGi-fied >>>> Spring MVC web app., and especially with detailed instructions on how to >>>> integrate and deploy OSGi runtime to Tomcat? >>>> Is it even possible today to have typical Spring MVC apps (with >>>> DispatcherServlet and all that) to be deployed in Tomcat and have shared >>>> OSGi services running and shared amongst them, without any trickery like >>>> Equinox HttpServletBridge, etc. >>>> I'm new to OSGi, so please don't judge my question too much :-) >>>> Regards, >>>> Dmitriy.
-- Costin Leau Senior Software Engineer SpringSource (formerly Interface21) Limited - Spring Services from the Source Email: costin.l...@SpringSource.com http://www.SpringSource.com Registered in England and Wales: No. 5187766 Registered Office: A2 Yeoman Gate, Yeoman Way, Worthing, West Sussex, BN13 3QZ, UK
This e-mail and any attachments transmitted with it are strictly confidential and intended solely for the person or entity to whom they are addressed. Unauthorised use, copying, disclosure or distribution is prohibited. If you receive this e-mail in error please notify the sender immediately and then delete it along with any attachments. E-mails should be checked by the recipient to ensure that there are no viruses and SpringSource does not accept any responsibility if this is not done. Any views or opinions presented are solely those of the author and do not necessarily represent those of SpringSource.