| From | Sent On | Attachments |
|---|---|---|
| John Gordon | Jan 7, 2009 5:22 pm | |
| Jose Noheda | Jan 8, 2009 1:24 am | |
| John Gordon | Jan 8, 2009 11:18 am | |
| Jose Noheda | Jan 9, 2009 1:22 am | |
| John Gordon | Jan 9, 2009 9:17 am | |
| Kudinov, Aleksey | Jan 9, 2009 11:05 am | |
| Jose Noheda | Jan 9, 2009 12:02 pm | |
| John Gordon | Jan 9, 2009 2:49 pm | |
| Jose Noheda | Jan 9, 2009 3:46 pm | .java, .xml, .xml |
| John Gordon | Jan 9, 2009 8:07 pm | |
| Jose Noheda | Jan 10, 2009 2:19 am | |
| Kudinov, Aleksey | Jan 20, 2009 6:45 am | |
| Joe Walker | Jan 20, 2009 8:38 am |
| Subject: | Re: [dwr-user] DWR 3 annotations with Spring Injection | |
|---|---|---|
| From: | John Gordon (john...@gmail.com) | |
| Date: | Jan 8, 2009 11:18:00 am | |
| List: | net.java.dev.dwr.users | |
Jose,
Great news! Thanks to your last post, I was able to put all the DWR and Spring annotations into the java files, leaving my spring config files pretty much empty (except for calls to load annotations for the systems). There are two remaining issues I'm finding with the DWR integration I was hoping you could lend some help with:
Outstanding Items:
--DWR works in script, but the test page doesn't do anything when my method is invoked (a simple echo method that returns a string).
--It sounds like you don't need to create a specific DWR servlet, but when I don't, anything under dwr doesn't work.
My Testing reveals the following:
If I remove the servlet for DwrSpringServlet and create a mapping in web.xml like this:
<servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping>
DWR is loaded correctly,but I get the following error when hitting any of the [myApp]/dwr links:
javax.servlet.ServletException: No adapter for handler [org.directwebremoting.spring.DwrController@922652]: Does your handler implement a supported interface like Controller?
This is the contents of my applicationContext.xml file:
<context:component-scan base-package="com.gordonjl"/> <context:annotation-config />
<dwr:annotation-config/>
<dwr:controller id="dwrController" debug="true"/>
<dwr:url-mapping />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
When I replace the <dwr:url-mapping /> with this:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="alwaysUseFullPath" value="true"/> <property name="order" value="3"/> <property name="mappings"> <props> <prop key="/engine.js">dwrController</prop> <prop key="/util.js">dwrController</prop> <prop key="/interface/**">dwrController</prop> <prop key="/call/**">dwrController</prop> <prop key="/dwr/**">dwrController</prop> </props> </property> </bean>
I still get the above error:
2009-01-08 14:09:41,210 DEBUG [org.springframework.web.servlet.DispatcherServlet] - DispatcherServlet with name 'dispatcher' received request for [/test/dwr] 2009-01-08 14:09:41,210 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Bound request context to thread: org.apache.catalina.connector.RequestFacade@3a23cb 2009-01-08 14:09:41,211 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Testing handler adapter [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter@1e01f7 ] 2009-01-08 14:09:41,211 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@3a23cb 2009-01-08 14:09:41,211 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Could not complete request javax.servlet.ServletException: No adapter for handler [org.directwebremoting.spring.DwrController@6be60b]: Does your handler implement a supported interface like Controller?
The call to /util.js will return a 404, btw.
At this point, I'd like to resolve why the test pages aren't working--that's blocking my development--, but it would be nice to have the SpringServlet mapping issue resolved so I can keep my web.xml as clean as possible. What gives?
Thanks,
John
On Thu, Jan 8, 2009 at 4:25 AM, Jose Noheda <jose...@gmail.com> wrote:
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,
John
--
------------------------------------------------------------------ John Gordon john...@gordonjl.com http://gordonjl.com
--
------------------------------------------------------------------ John Gordon john...@gordonjl.com http://gordonjl.com






.java, .xml, .xml