Spring Archives - Intertech Blog

JAXB Tutorial: Customized Namespace Prefixes Example using NamespacePrefixMapper

Do you need to specify what namespace prefixes are used in your JAXB marshaled XML? For example, do you want to see  in the generated XML instead of ? If so, this JAXB tutorial will walk you through those steps. If you are using the default JAXB implementation provided with Java 6 or later, you can configure the namespace prefixes by extending the  and setting a property to tell the marshaller to use your extension. For more details on marshalling JAXB objects to XML, review… Read More

JAXB Tutorial: How to Marshal and Unmarshal XML

This JAXB tutorial describes how to use JAXB to marshal and unmarshal XML strings using either Spring or the standard javax.xml.bind interfaces. The samples below are using XML strings instead of files, but could easily be adapted to files if needed. Spring’s Jaxb2Marshaller Configuration To use Spring’s , you will need the spring-oxm dependency, which you may already have, since it is used by other major spring components. To configure the  in your Spring context, add the config XML below.  Be sure to add… Read More

Spring Security Active Directory LDAP Example

At a recent client, I was tasked with securing their web applications using Spring Security and their internal Active Directory (AD) LDAP server. I scoured the web and went through a lot of trial and error until I finally found the configuration that worked in their environment.  Based on some of the comments and questions I found on the web, the problems that I was facing seemed to be shared by others. Here’s a Spring Security Active Directory example to show how… Read More

Spring Integration – Enterprise Integration Veg-O-Matic

Do you remember some of those crazy kitchen utensil commercials during the 70’s and 80’s?  One of my favorites was the Veg-O-Matic.  The slogan for that tool was that “it slices, it dices”…and of course who can forget “but wait there’s more!” I have been working on some Enterprise application integration projects recently.  We are using the Spring Integration framework to accomplish our work.  This project within the Spring Framework portfolio amazes me.  It reminds me of the Veg-O-Matic.  It… Read More

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