Reputation: 448
I have a GWT application in which I would like to add Spring, and mainly use Spring with JdbcTemplate to handle my database connection and DAO model. I am fairly experienced working with GWT but am just starting to learn Spring.
What is not clear to me is where and how I would initialize spring in my GWT application? I need to initialize an application context somewhere I assume. Is it possible to do this with an RPC method invoked from onModuleLoad() in the front-end, but will the objects still be available later on if I do that?
Basically I am looking for a basic overview of how and where to initialize Spring in the back-end so that I can start developing and experimenting with Springs components.
Thank You!
Upvotes: 2
Views: 838
Reputation: 11625
Several years ago, I did a Spring-GWT integration with roughly the following steps:
Create a base RemoteServiceServlet class that have methods for acquiring spring ApplicationContext from ServletContext. This can be done using something like following:WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
Make all the RPC servlets extends this base class.
The only problem with this approach was that the RPC servlet are not them-self not created by Spring so you cannot have their dependencies injected.
Now you can employ third-party frameworks for spring-gwt integration. For example GWT Platform's Dispatch module lets you configure your action handler's as spring beans. Such solutions basically employ a single RPC servlet provided by the framework. This framework RPC servlet is responsible for instantiating your server-side handlers and invoking them. If you are willing to learn these additional frameworks, they might be better long-term solutions than the one I outlined above.
Upvotes: 1