Spring Talks by Keith Donald
Spring has largely been my focus for the last few years so I was happy to see one of the Spring Source crew stepping up at NFJS. Keith Donald is the lead of almost all Spring web related technologies and he tends to give a very down to earth, code centric presentation so I devoted all of my final day to his talks.
Someone in the audience asked Keith if he missed the common XML file that shows exactly how all your beans are wired when you move to annotation driven POJOs and that question is an important one. I've recently become much more comfortable with developing Spring applications due to the Spring Facet in IntelliJ. Moving to annotations tends to make me question exactly which resource or component is plumbed in to fill a dependency. Keith mentioned that an emerging best practice is to use annotations for self describing application dependencies, XML for infrastructure concerns. He also gave a soft sell for Spring IDE to show a nice dependency graph regardless of annotations or XML.
Spring 2.5 is downright giddy with it's extensive use of annotations and it didn't really dawn on me until Keith's talk that it might be the better way to go in some scenarios. I've traditionally balked a little bit at the extensive use of annotations as it feels very invasive to the code at hand, especially when the annotations are Spring specific. More importantly, swapping out facilities for testing purposes is not trivial when you are doing component scanning and autowiring with annotations. I think Keith articulates an appropriate scenario for use though. Swapping out mock classes via XML is not a benefit that is needed as much for application dependencies as it is one that is needed for infrastructure (data access, email service, file reader, etc...). Go nuts with annotations at the app level, but use a good editor and keep the XML where it belongs for infrastructure pieces.
Keith spent a good amount of time in all of his talks using an IDE focused on Spring MVC controllers. The thing that stood out to me was how Spring web controllers are truly just POJOWAs now (I know that's not a term that will stick but a distinction needs to be made between POJOs and POJOs with annotations). This means that you will rarely see HttpServletRequest or ModelAndView type classes in these POJOs. What's the benefit here? You don't have to waste many of your test cycles mocking up the container objects. Wanna test your login method on the controller? Send in a User object and a String password and then validate whether you are getting a success or error redirect back. Very simple, and anything that we can do to lower the barrier of entry to good testing is well worth it.
Keith demonstrated another key change in coding Spring apps is the impact that Rails has had on the Spring community. The focus has shifted in Spring 2.5 to more sensible defaults and a true convention over configuration model. Controllers in Spring web apps now mimic Rails controllers in URL and request parameter resolution. Additionally, there are a set of special parameter types that are automagically injected. An arg of type Principal will be supplied by the container if the user is already logged in. Very cool.
One final note on the Spring web side. Why do we have another javascript framework? If you have improvements to make to DOJO, please just contribute them to DOJO. Don't create an abstraction layer over DOJO that does what you need. We have finally whittled the .js framework comparison down to a handful in my mind (prototype/scriptaculous, dojo, jquery, yui, and ext). Don't lead us back in the other direction.
Conference conclusion
NFJS again provided some immediate exposure to worthy technologies and processes. I was able to touch base with a lot of people in the Java community that I hadn't seen in some time and I feel like I have more tools in my belt than when the conference started. A special note to the organizers though. If the prices go up again next year while the number of conferences goes up as well, then you won't see me there for the first time in 4 years. It was evident to me this year that the conference is not the value that it was 2 and 3 years ago. If the trend continues, I'd rather spend my training dollars on codemash, erubycon, and books.
Sunday, July 27, 2008
Subscribe to:
Post Comments (Atom)
2 comments:
Todd,
I just wanted to quickly address your concerns about Spring JavaScript and perhaps makes our intentions more clear. The point of Spring JS is not to introduce another framework so much as it is to be one central place to provide a common integration approach between the best Javascript libraries and a Spring-based web application.
The major JS libraries like Dojo are (much like Spring) intentionally quite flexible in the number of different ways they give you to approach a problem. Spring JS aims to be a bit more prescriptive by collecting the approaches we believe to be most useful and providing a simple way to apply them, while at the same time still allowing full access to the underlying Javascript library when needed. It is meant to be a distillation of best practices that are specific to a Spring application. The code therein is thus not really appropriate for contributing directly back to Dojo, but we at the same time are actively maintaining close communication with the Dojo team to see determine how we can collaborate to the benefit of both of our communities. We are also still keen on the idea of providing similar implementations for the other major Javascript libraries in use by our community. One analogy I like to commonly use is that Spring JS can be thought of in a similar manner to Spring's support for various ORM technologies.
Take our Ajax remoting support for example. Dojo gives you a great number of ways to communicate with a server via XHR and is quite flexible, but this comes at the cost of you having to write your own response handling infrastructure. Spring JS provides the response handling infrastructure for a specific technique of rendering back a partial response from a Spring MVC controller. It provides not only the client-side infrastructure for generating the request and automatically handling the response, but also some server-side MVC extensions that make it possible to generate this partial response using the same controller method that would be used in the non-Ajax case, providing for simple and automatic graceful degradation. You will see these ideas taken even further in Spring 3.0.
Hope that helps, and thanks for your support!
-
Jeremy Grelle
Spring JS Lead
Jeremy,
I appreciate you taking the time to further expand upon the Spring-JS offering. I hope you don't view it as a knock against the need for features you've provided, but rather a question of where that need should be best implemented.
Your example using AJAX with a server side Spring MVC controller more clearly articulates the reasons for your approach and I agree with that point. If Spring-JS remains a collection of Spring specific JavaScript best practices, then I think you've solved the problem well. If it starts adding JavaScript best practices that transcend beyond Spring, then I believe they should be committed to DOJO, JQuery, YUI, etc...
Post a Comment