Spring

Spring Framework’s WebDataBinder

Last week, I was just outside our nation’s capital teaching Spring Web MVC Framework to a wonderful group of people working for the National Institute of Health (NIH).  They are getting ready to move a collection of Struts 1 projects to Spring Web MVC.  Some questions and discoveries around Spring Web MVC’s @InitBinder operations seemed a good fit for this week’s post. Spring Web MVC Command Beans Part of my Spring MVC class is dedicated to teaching students how to… Read More

How to use Spring’s WebApplicationInitializer

The DispatcherServlet has always served as the doorway component or “front controller” in a Spring Framework Web MVC application.  It’s job has been and still is to marshal requests to other components in the Spring MVC application backend and to orchestrate a response back to clients. DispatcherServlet and the web.xml Until Spring 3.1, the DispatcherServlet had to be registered with the Servlet container via the standard Web application web.xml file. The following elements had to be added to register the DispatcherServlet…. Read More

Spring 4 Generic Qualifiers

This post is part of my series on some of the new Spring 4 features. As of Spring 4, generic types can be used to determine what bean should be dependency injected (either by XML or annotation). Wiring By Generic Type An example can help clarify this new feature.  Assume you defined your DAO by generic interface (if you haven’t studied Java generic typing, you may want to visit here to learn more). Now consider a case were two beans are… Read More

Spring 4 Meta Annotations

The Spring Framework started adding annotations to Spring development with version 2.  Each release has added more annotations.  Annotations provide a powerful means to define and wire your beans, configure cross cutting concerns (like transactions) and much more.  However, given the number of annotations added to your POJO classes to provide for Spring stereotyping, dependency injection, transactions, AOP, etc., you may forget what the actual business of the class is all about.  What’s more, you have to add the same annotations to… Read More

Spring 4 – Conditional Bean Configuration

As part of my series on the new features in Spring Framework, version 4, I’d like to present how to use the new Condition interface and @Conditional annotation.  Spring 4 was just release in GA form this week.  You can check my past post for some of the highlights of this release. There are times when you would like the creation and dependency injection of a bean to depend on circumstances.  Those circumstance could be what operating system your application is… Read More

Spring 4 Ordering Autowired Collections

Spring 4 offers an array of new features.  As with all releases, some of the new features are big and impactful.  Others are tiny but helpful. Autowiring Collections One of the new small features in Spring 4 is the ability to use @Order with autowiring.  There has always been the ability to have Spring automatically collect all beans of a given type and inject them into a collection or array.  Since Spring 2.5, this was most commonly accomplished by annotation as… Read More

Spring Framework – Version 4 Due Out Tomorrow!

Happy holidays to everyone.  I hope you are enjoying this festive time of year and you get a little down time during the holidays.  If you are like me, you might enjoy using some of your down time to update yourself on the Java/open source APIs that have appeared this year.  There have been quite a few advances this year. In particular, you may want to spin up on Spring 4.  Spring Framework 4 GA (general availability) is due out tomorrow – Dec… Read More

Understanding Spring MVC Model and Session Attributes

As a Java Web application developer, you quickly learn about the request (HttpServletRequest) and session (HttpSession) scopes.  Understanding these scopes and how to work data and objects in and out of these scopes is critical to designing and building Web applications in Java.  [For a quick tutorial on request and session scopes, here is a post in StackOverflow that can help.] Spring MVC Scopes When I started writing Web applications in Spring MVC, I found the Spring model and session attributes to… Read More

Spring’s ContentNegotiatingViewResolver

When I teach Spring, I tell my students that Spring’s MVC architecture is one that allows the human facing Web site to easily be adapted to address non-human users.  That is, the Spring MVC architecture easily supports RESTful Web services.  In fact, Spring MVC applications can address human and machine users alike without the need for separate controller components or alternative request mapping paths. By adding the ContentNegotiatingViewResolver, along with a few extra XML, JSON or alternative formatting beans, your other Web application… Read More

Spring Expression Language – a Spring 3 Feature You May Be Forgetting?

Spring Expression Language (SpEL) was one of the new features that debuted with Spring 3.0.  Spring 3.0 was released back in December 2009.  So that makes this feature a little less than four years old as of this writing.  Yet, in my informal survey of teams using Spring, I am always a bit surprised at how few applications are taking advantage of this powerful feature today. So in this post, I’d like to provide a quick tutorial on SpEL and… Read More