« Return to Thread: Spring - DWR little contribution

Spring - DWR little contribution

by XMaNIaC :: Rate this Message:

Reply to Author | View in Thread

Hi,

It seems a lot of people still have problems configuring DWR inside Spring. Looking for a way to improve it I tried to mix annotations with Spring. This is the result.

The code needs to be polished a lot (consider it a proof-of-concept as always). Basically, you only have to define this beans in the XML:

<dwr:configuration />
<dwr:controller id="dwrController" />
<bean class="org.directwebremoting.spring.DwrServicePostProcessor" p:basePackages="..." />
<bean class=" org.directwebremoting.spring.DwrHandlerMapping" />

And it will automatically remote any spring beans annotated with DwrService / RemoteMethod. I think it's a good start.

Next steps involve:

* Extending the schema. Something like <dwr:annotation-configured />. I didn't want to mess with DWR code if at all possible. Adding it should be pretty straightforward.
* Refactoring (it shares some code with DwrNamespaceHandler)
* Add some convention with package names and bypass the basePackages property (I tried it but Package.getPackages() keep forgetting the WEB-INF/classes packages for some reason beyond my knowledge)
* Getting a little help from SpringSource so we don't need to extend some classes. Good extension points in ClassPathBeanDefinitionScanner would save us lots of trouble

Comments are welcomed!

Regards,






<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                            http://www.directwebremoting.org/schema/spring-dwr
                            http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!-- DWR -->
    <dwr:controller id="dwrController" debug="true" />

    <dwr:configuration />
   
    <bean class="org.directwebremoting.spring.DwrServicePostProcessor" p:basePackages="com.internna.dwr.sample" />
    <bean class="org.directwebremoting.spring.DwrHandlerMapping" />

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>DWR-SpringAnnotationConfiguration</display-name>
        <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>
  <welcome-file-list>
                <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
</web-app>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

RemotedBean.java (688 bytes) Download Attachment
DwrHandlerMapping.java (1K) Download Attachment
DwrService.java (636 bytes) Download Attachment
DwrServicePostProcessor.java (2K) Download Attachment
DwrServiceScanner.java (6K) Download Attachment
index.jsp (1K) Download Attachment

 « Return to Thread: Spring - DWR little contribution