I need to use Embedded Jetty, DWR and my own beans in one Spring context. In order to do it I need to execute this steps:
1. Describe Jetty classes as Spring beans without using WebAppContext and WEB-INF/web.xml because in this case DwrServlet will be injected by Jetty code but I need to inject DwrServlet from Spring context.
The best entry point for second task is DwrSpringServlet and SpringConfigurator classes. SpringConfigurator class can be used without any changes, but it is impossible to use DwrSpringServlet as is due to this error:
ERROR DwrSpringServlet - init failed
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:86)
at org.directwebremoting.spring.DwrSpringServlet.init(DwrSpringServlet.java:88)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:442)
....
To resolve this problem I define DwrSpringServlet as implements BeanFactoryAware by example of DwrController and remove retrieving the configurators from Spring because I have not bean with hardcoded name DwrNamespaceHandler.DEFAULT_SPRING_CONFIGURATOR_ID. Patch is attached.
So, I can define next part of Spring context which will be looks like:
Another option is DwrServlet modification to support configuration from any Configurator interface instead of hardcoded Spring dependency in DwrSpringServlet.
Is it possible to support this configuration way in next DWR version out of box (and maybe include this example)?
Hi,
I need to use Embedded Jetty, DWR and my own beans in one Spring context. In order to do it I need to execute this steps:
1. Describe Jetty classes as Spring beans without using WebAppContext and WEB-INF/web.xml because in this case DwrServlet will be injected by Jetty code but I need to inject DwrServlet from Spring context.
2. Configure DwrServlet from Spring context.
First task can be implemented like this:
<bean id="jetty" class="org.mortbay.jetty.Server" init-method="start" destroy-method="stop">
<property name="connectors">
<list>
<bean class="org.mortbay.jetty.nio.SelectChannelConnector">
<property name="port" value="8080"/>
</bean>
</list>
</property>
<property name="handlers">
<list>
<bean class="org.mortbay.jetty.handler.ResourceHandler">
<property name="resourceBase" value="web"/>
</bean>
<bean class="org.mortbay.jetty.servlet.Context">
<constructor-arg><null/></constructor-arg>
<constructor-arg>
<bean class="org.mortbay.jetty.servlet.SessionHandler"/>
</constructor-arg>
<constructor-arg><null/></constructor-arg>
<constructor-arg>
<bean class="org.mortbay.jetty.servlet.ServletHandler">
<property name="servlets">
<list>
<bean class="org.mortbay.jetty.servlet.ServletHolder">
<constructor-arg ref="dwrServlet"/>
<property name="name" value="dwr"/>
<property name="initParameters">
<map>
<entry key="debug" value="true"/>
<entry key="pollAndCometEnabled" value="true"/>
<entry key="continuationsEnabled" value="false"/>
</map>
</property>
</bean>
</list>
</property>
<property name="servletMappings">
<list>
<bean class="org.mortbay.jetty.servlet.ServletMapping">
<property name="servletName" value="dwr"/>
<property name="pathSpec" value="/dwr/*"/>
</bean>
</list>
</property>
</bean>
</constructor-arg>
<constructor-arg><null/></constructor-arg>
<property name="contextPath" value="/"/>
</bean>
</list>
</property>
</bean>
The best entry point for second task is DwrSpringServlet and SpringConfigurator classes. SpringConfigurator class can be used without any changes, but it is impossible to use DwrSpringServlet as is due to this error:
ERROR DwrSpringServlet - init failed
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:86)
at org.directwebremoting.spring.DwrSpringServlet.init(DwrSpringServlet.java:88)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:442)
....
DwrSpringServlet.java:88 is:
WebApplicationContext webappContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
To resolve this problem I define DwrSpringServlet as implements BeanFactoryAware by example of DwrController and remove retrieving the configurators from Spring because I have not bean with hardcoded name DwrNamespaceHandler.DEFAULT_SPRING_CONFIGURATOR_ID. Patch is attached.
So, I can define next part of Spring context which will be looks like:
<bean id="dwrServlet" class="org.directwebremoting.spring.DwrSpringServlet">
<property name="configurators">
<list>
<bean class="org.directwebremoting.spring.SpringConfigurator">
...
</bean>
</list>
</property>
</bean>
Another option is DwrServlet modification to support configuration from any Configurator interface instead of hardcoded Spring dependency in DwrSpringServlet.
Is it possible to support this configuration way in next DWR version out of box (and maybe include this example)?
Joe Walker added a comment - 14/Mar/07 11:32 AM The patch that I've just attached actually applies. I want to get comment from the Spring guys before I apply it.
More detail and proposed patches: https://dwr.dev.java.net/issues/show_bug.cgi?id=136