atom feed13 messages in net.java.dev.dwr.usersRe: [dwr-user] DWR 3 annotations with...
FromSent OnAttachments
John GordonJan 7, 2009 5:22 pm 
Jose NohedaJan 8, 2009 1:24 am 
John GordonJan 8, 2009 11:18 am 
Jose NohedaJan 9, 2009 1:22 am 
John GordonJan 9, 2009 9:17 am 
Kudinov, AlekseyJan 9, 2009 11:05 am 
Jose NohedaJan 9, 2009 12:02 pm 
John GordonJan 9, 2009 2:49 pm 
Jose NohedaJan 9, 2009 3:46 pm.java, .xml, .xml
John GordonJan 9, 2009 8:07 pm 
Jose NohedaJan 10, 2009 2:19 am 
Kudinov, AlekseyJan 20, 2009 6:45 am 
Joe WalkerJan 20, 2009 8:38 am 
Subject:Re: [dwr-user] DWR 3 annotations with Spring Injection
From:Jose Noheda (jose@gmail.com)
Date:Jan 8, 2009 1:24:33 am
List:net.java.dev.dwr.users

AFAIK you can't completely remove the XML files. With your current configuration the most you can achieve is

@RemoteProxy( creator = SpringCreator.class, creatorParams = @Param(name = "beanName", value = "remoteTest"), name = "RemoteTest" )

and declare all the classes. Other option would be to keep your current code and use <dwr:annotation-config /> but that involves XML. By the way DwrServlet is not mandatory when using annotations.

Regards,

On Thu, Jan 8, 2009 at 2:22 AM, John Gordon <john@gordonjl.com>wrote:

Hey, folks,

Is there a way to have a DWR RemoteProxy class work with Spring annotated injection? Here's my situation.

I have a class I want DWR to use that uses an injected class. Spring will be managing the injection. I've been able to do this by defining a bean in Spring's configuration as follows:

<bean id="echoService" class="com.gordonjl.dwr.InjectedServiceImpl"/>

<bean id="remoteTest" class="com.gordonjl.dwr.RemoteTestImpl"> <constructor-arg ref="echoService"/> <dwr:remote javascript="remoteTest"> <dwr:include method="echo"/> </dwr:remote> </bean>

and I'm using the spring-aware DWR servlet to make it possible for DWR to use spring configs:

<servlet> <servlet-name>dwr</servlet-name>

<servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping>

Here's where my issue comes in. I don't like config files. In fact, I despise and want to get rid of them. I'm able to remove config files for my Spring components by using Spring's annotations. In the above spring config code for RemoteTestImpl, I would do this:

@Component public class RemoteTestImpl implements RemoteTest {

private InjectedService theService;

@Autowired public RemoteTestImpl(InjectedService theService) { this.theService = theService; }

public String echo(String echoText) { return theService.echo(echoText); } }

This works just great, but, in order to get rid of the spring config, I need to use DWR's annotations, too. This is what I think I should have after applying the dwr annotations to the above class:

@Component @RemoteProxy public class RemoteTestImpl implements RemoteTest {

private InjectedService theService;

@Autowired

public RemoteTestImpl(InjectedService theService) { this.theService = theService; }

@RemoteMethod public String echo(String echoText) { return theService.echo(echoText); } }

The problem with this is that the documentation for using DWR annotations says that I have to use org.directwebremoting.servlet.DwrServlet and provide the classes it is to parse. My concern is that this DwrServlet isn't spring aware. It will find the classes, read the dwr annotations and, when a remote call is made, it will instantiate the Remote class directly, not through the Spring framework. The result of this is that the injected class in the constructor wouldn't be injected. That leads me to two questions:

Is there yet a servlet for DWR that reads annotations _and_ that accesses the classes through the Spring framework? Is there also a niftier way parse DWR annotated classes instead of explicitly stating them in the web.xml file?

Thanks,