Spring4gwt, or Spring’s harmony for GWT


I’ve had an idea itching at me for awhile now, which started shortly after building a complex enterprise application using GWT connected to Spring services on the server. There are countless blogs out there describing various ways to wire up Spring with GWT, and Google’s own Gin is quite adequate for client-only dependency injection. But what I’d really like is something that ties this all together, and in the true spirit of GWT, makes it easy for a seasoned Java developer to apply proven, consistent DI practices in both the client and server using the Spring knowledge they likely already have.

My vision is basically this:

@Component
public class SomeGWTComponent {

	// Some other client-side component
	@Autowired
	private MyWidget widget;

	// A remote service proxy to a server-side Spring service
	@Autowired
	private MyService service;

	public void doSomething() {

		widget.doClientStuff();

		...

		service.doServerStuff("data", new AsyncCallback<String>() {

				public void onFailure(Throwable caught) {
					...
				}

				public void onSuccess(String result) {
					...
				}
			});
		}
	}
}

It’s important that MyService is a vanilla Spring service on the server – no extension of RemoteServlet required – and that MyWidget is any other GWT component. Injection should occur when the component is created, potentially with varying scopes just like on the server, and potentially also with @PostConstruct support for code to be executed after injection, leaving the constructor available for any pre-injection initialization. And finally, as much work as possible should be done during GWT compile minimize the run-time cost.

The approaches to GWT lookup/injection I’ve seen out there have at least one the following gaps:

  • They’re client-only (Gin)
  • They’re largely run-time, and slow (MVC helpers in component libraries like GXT)
  • They involve SpringMVC or other unnecessary server-side complexity (most blog guides)

So I’m going to try to bring this altogether in one simple library with the following goals:

  • Simplicity: Access Spring services from the client through a generic exporter; no service-specific mappings in web.xml, forced type hierarchy (services should be existing Spring POJO’s), or dependency on SpringMVC. In other words, when a new Spring service is added to the server it should require zero configuration changes to be accessible in the client if desired.
  • Consistency: Client-side dependency injection with native Spring look and feel; freedom to inject private members, via constructor, or via getters/setters with same Spring annotations and conventions that are already familiar.
  • Performance: Do all the heavy lifting with GWT generators to keep the client lean.

Behold, spring4gwt where I’ll do my best to make this a reality! The initial version captures objective #1, bringing together a generic servlet for exposing Spring services without turning each into its own RemoteServlet mapped in web.xml. Up next: accessing those services with Spring DI in the client!

, , , ,

  1. #1 by José on July 22, 2009 - 2:02 am

    Very nice. Looking forward to future releases.

  2. #2 by Kalyan on August 23, 2009 - 9:04 am

    Hello,
    I was looking to do exactly what you have in mind. But not being successful after looking at your project on google code.
    I detailed the problem here.

    http://spring4gwt.blogspot.com/

    If you could help me with this problem.. that’ll be great.

    Thanks
    Kalyan

  3. #3 by Dustin on August 23, 2009 - 7:50 pm

    Kalyan :

    Hello,
    I was looking to do exactly what you have in mind. But not being successful after looking at your project on google code.
    I detailed the problem here.

    http://spring4gwt.blogspot.com/

    If you could help me with this problem.. that’ll be great.

    Thanks
    Kalyan

    This does look like a class file version issue. I just downloaded the posted spring4gwt-0.0.1.jar and ran a javap -verbose SpringGwtRemoteServiceServlet to make sure and it was built with target 1.5 so it should work fine with the jdk you have selected. I also built the demo projects with Java 5 (on Windows) and was able to run them correctly. Is there any other place in your Eclipse project that you may have selected Java 6 for compilation of server-side files? You could also try building the spring4gwt jar from source just to see if it works (build file specifies source/target 1.5, but I’ve only tested on Windows and Linux).

  4. #4 by Niel on September 17, 2009 - 7:32 pm

    Nice blog post. I have been working on GWT and Spring integration using DWR, but I will definitely being giving this a try.

  5. #5 by Jaen Swart on June 4, 2010 - 1:54 am

    Hi,

    Did you stop development of spring4gwt or are you just busy at the moment :-) I see the last update is July 2009

  6. #6 by Dustin on June 11, 2010 - 8:57 pm

    I’ve been busy, but also with a final release of Google Gin I’ve realized that most of the advanced features I was thinking about are much better solved by Gin. So the basic RPC integration that’s there is all I’ve ended up needing and like most open-source project my desire to put more into it is driven entirely by need. :) I’d highly recommend Gin for anyone implementing fully-featured dependency management in their GWT app, not to mention it works seamlessly with Guice for unit testing.

  7. #7 by Hotels in Los Angeleshotel dealslate lodge inn discounts. on April 29, 2014 - 6:17 am

    Thanks for sharing such a good thought, paragraph is fastidious, thats why i have read it entirely

  8. #8 by Hotels in London on October 4, 2014 - 7:27 pm

    I’ve been exploring for a little for any high quality articles or weblog posts on this sort of house .
    Exploring in Yahoo I eventually stumbled upon this website.
    Reading this information So i’m glad to express that I’ve an incredibly
    good uncanny feeling I came upon exactly what I needed. I most
    indisputably will make certain to do not disregard this website and provides it a glance on a constant basis.

  9. #9 by Chengduhotel specialsvery last minute on November 20, 2014 - 6:20 am

    It’s going to be finish of mine day, but before finish I am
    reading this great paragraph to improve my knowledge.

  10. #10 by Reserve now on January 15, 2015 - 6:54 am

    I do consider all the concepts you’ve introduced to your post.
    They’re very convincing and can definitely work.
    Still, the posts are very brief for starters. Could you please prolong them a little from next time?

    Thank you for the post.

  11. #11 by Fha Loan Limits Atlanta Georgia on January 29, 2015 - 5:27 am

    Myth #2 – “I must have good credit since I keep getting credit card offers in the mail. Bankrate offers an example on how the one-time funding fee works:. The FHA was required to pay off lenders whenever borrowers defaulted on FHA insured loans.

  12. #12 by 2014 fha fha Loan limits arizona on April 21, 2015 - 4:51 pm

    Many people are stuck in between, neither being able to sell their current property, nor applying for a mortgage due to
    the fear of implementation of stricter rules and requirements.
    Lenders are required to be approved by the agencies
    in order to make loans to borrowers who qualify. The loan starts at the start of construction and ends when you finish and move in.

  13. #13 by Hermine on December 23, 2015 - 9:22 pm

    A loan amount sufficient to buy the car
    can be raised by them. This way, you will be aware of one’s exact credit
    score. You may get away with a down payment as
    little as 5%, but 20% will ensure lower rates.

(will not be published)