On Wednesday, January 5, 2011 11:05:10 PM UTC+1, Eric Andresen wrote:
>
> I'm using the 2.1.1 RequestFactory in a Spring environment. I would
> like to use my Spring Service class to provide both my Entity Locator
> and my RequestContext methods.
>
> I can define my object's requestContext as:
>
> @Service(value=MyObjectService.class,locator=SpringServiceLocator.class)
> public interface MyObjectRequest extends RequestContext { ... }
>
> and give it a Service Locator that retrieves the service class for the
> current scope:
>
> public class SpringServiceLocator implements ServiceLocator
> {
> @Override
> public Object getInstance (Class<?> clazz)
> {
> return
> ApplicationContextProvider.getContext().getBean(clazz.getSimpleName(),clazz);
>
> }
> }
>
> which finds a Service that looks like:
> @Scope("session")
> @Service("MyObjectService")
> @Transactional(isolation = Isolation.DEFAULT, propagation =
> Propagation.REQUIRED)
> public class MyObjectServiceImpl extends Locator<MyObject, Long>
> implements MyObjectService { ... }
>
> This part works great.
>
Actually, no: RequestFactory aggressively caches locators and service
instances and re-uses them across requests. So your service won't have it's
@Scope("session") applied at all (unless Spring actually proxies it to
always hit the "correct" instance? – disclaimer: I don't use Spring).
Is there a way to point the Entity's Locator to this class using
> something like a ServiceLocator? What I'd like is something like
> this:
>
> @ProxyFor(value=MyObject.class,locator=MyObjectService.class,locatorLocator=SpringServiceLocator.class)
>
>
> public interface MyObjectProxy extends EntityProxy { ... }
>
> I'm trying to keep all of my object finders in my MyObjectService
> layer, but I don't want GWT to construct it, I want to use a locator
> to find the one Spring has already instantiated for me.
>
Then you have to define a ServiceLayerDecorator and override createLocator
to use Spring instead of the default implementation (which instantiates it
using a no-arg constructor).
To use that ServiceLayerDecorator, you have to extend RequestFactoryServlet
and pass the decorator to the servlet's constructor.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.