Apr 4th, 2007, 06:48 AM
how to expose sip/Servlet as Spring beans ?
I want to expose a sip/servlet as a bean managed by spring framwork.
<bean id="mysipservlet" class="com.basic.mysipservlet">
<property name="host" value="basic.org">
<bean id="myhttpservlet" class="com.basic.myhttpservlet">
<property name="sipservlet" ref="mysipservlet"/>
the pb is the sip servlet instance is managed by the sip servlet container and not by spring, wich spring's interface have to be implemented by my sip servlet (like setBean("mysipservlet",this)) ? wich Spring API should be used to programmaticaly expose my sipservlet instance as a spring bean ?
ps:my sipservlet use actualy spring beans via getBean in his init method.
Apr 4th, 2007, 09:19 AM
So your goal is to remove the getBean() calls and make it Spring independent at the end?
Apr 4th, 2007, 09:32 AM
actually the Spring ContextListener is declare in my web.xml descriptor. it load all bean resources and specially a mysipservlet bean (spring create an instance). however this bean is already loaded by the sipservlet container and declare in an other descriptor (eg sip.xml) but Spring didn't see this instance and i am face to 2 instances of my sipservlet bean.
so how spring could hook the sip/servlet container ? or how my sipservlet could be collaborate to spring container ?
i am looking to Factory-bean and a getInstance() method to retrieve my sip servlet intance ....
Apr 4th, 2007, 10:31 AM
I think you have two options. If you just need access to Spring application context in your Sip servlet you can use Spring's WebApplicationContextUtils to retrieve it.
If you really need it the other way around (the Sip servlet in your Spring application context) then there are options as well. But it heavily depends on how you can retrieve this servlet at all. If you know how to access it in plain Java code, I'm sure you can replace it with Spring and make it somehow Spring managed or at least usable in your application context.
Apr 4th, 2007, 04:31 PM
actualy from my sip servlet i use webapplicationcontextutils to retrieve spring beans.
my pb is actually in the other way.My first implmentation was access to my sip servlet as a static way mysipservlet.link() so i think factory-bean way will be a good way to investigate (in my sip servlet i have a getInstance method wich return getServletContext.getAttribute("mysipservlet"), however, my sipservlet instance comes after spring initialisation so the getinstance fail due to a null pointer
i continue to investigate
Apr 6th, 2007, 05:06 AM
my sipservlet singleton is created outside of Spring container but in the same servlet context (deployed in the same package). With the lazy-init option, my httpservlet can wait for mysipservlet init but when spring call mysipservlet 's getInstance method, i am face to a null pointer when i call getServletContext().
myspiservlet environnement is based on ServletContext (eg lookup sipFactory) so my question is :"From Spring context, how to lookup ServletContext ? witch api provide getServletContext() ?
Apr 7th, 2007, 03:48 AM
it's hard to give real advices without knowing the details. Especially as I haven't worked with sip yet.
But to answer your specific question regarding access to the servlet context: Have a look for ServletContextAware or its alternatives ServletContextFactoryBean, ServletContextAttributeFactoryBean or ServletContextParameterFactoryBean.
Hope this helps,
Apr 7th, 2007, 04:42 AM
There seems to be another thread with a similar topic.