Thanks for your insight on the matter. I was able to accomplish something
close to the desired behavior by placing a bridge between GWT and my service
class.
Doing this in conjunction with the SpringServiceLocator, I was able to only
cache this singleton class (kind of anyway, the ServiceLocator worked to
give me Spring's singleton instance, but the Entity's locator still created
a new one, which I then forced Spring to autowire also). From that point
since both are Spring managed, my session-based Service class is properly
wired when requests come in from the RF (in this case, I verified two
sessions got two different Service class instances, but shared the
singleton-scoped DAO)
@Service("MyObjectServiceProxy")
@Scope("singleton")
public class MyObjectServiceProxy extends Locator<MyObject, Long> implements
ApplicationContextAware
{
@Resource(name = "MyObjectDAO")
protected MyObjectDAO myObjectDAO;
@Resource(name = "MyObjectService")
protected MyObjectService myObjectService;
protected ApplicationContext context;
private transient Logger logger = LoggerFactory.getLogger(getClass());
public MyObjectServiceProxy()
{
logger.info("constructing MyObjectServiceProxy()");
context = ApplicationContextProvider.getContext();
if (context != null)
{
logger.info("Setting context from constructor");
setApplicationContext(context);
}
}
@Override
public void setApplicationContext (ApplicationContext arg0)
throws BeansException
{
logger.info("Setting application context for MyObjectServiceProxy");
try
{
// Attach this object to Spring
context = arg0;
context.getAutowireCapableBeanFactory().autowireBeanProperties(
this,
AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true);
}
catch (BeansException be)
{
logger.error("Bean exception autowiring service proxy: " +
be.getMessage());
}
}
...
public MyObject findMyObject(Long id)
{
return myObjectDAO.findMyObjectByPrimaryKey(id.intValue());
}
public MyObjectResult doSomethingToMyObject(MyObject obj)
{
return myObjectService.doSomethingToMyObject(obj);
}
...
}
Creating a ServiceLayerDecorator with a custom Locator does sound like a
better solution, I will look in to doing that so I don't have to have these
bridge classes hanging around everywhere.
Thanks again,
Eric
--
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.