SpringMVC example with Maven

Spring MVC is part of Springframework. It allow us to create application based on MVC design pattern in way that, we can leverage other features of Spring like authentication, ORM, AOP and others.

In Spring MVC core component is the DispatcherServlet{link}, It works as front-controller. All request are processed by DispatcherServlet. It is also responbile for deleting request to suitable handlers.


We are using standard Maven web project structure


        <!-- for compile only, your container will provide this  -->
        <!-- Spring-->
        <!-- JSTL -->

Request Controller

You can use or extend any of controller that comes from Spring or create you own by extendng AbstractController and implement handleRequestInternal method.

package com.techartifact.example.springmvc.controller;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloController extends AbstractController {

    private String message;

    public void setMessage(String message) {
        this.message = message;

    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        ModelAndView modelAndView = new ModelAndView("hello");
        modelAndView.addObject("message", message);
        return modelAndView;

Flow in a Spring MVC application is as follows:

The request is received by our DispatcherServlet

  1. DispatcherServlet has responsibility to find the controller for request. This process would be done in HandlerMapping phase.
  2. After controller has been found, DispatcherServlet will forward the request to Controller.
  3. Controller has the business logic to compute what model it will return to Dispatcher. It means Controller will return Model and view where it needs to displayed
  4. Once the ModelAndView has been dispatched to the DispatcherServlet from controller, DispatcherServlet will asociate the view name sent by the Controller with the specified view.
  5. After the view had been resolved, our DispatcherServlet will pass our Model object to the concrete View.


In this example we are using jsp for view

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <title>SpringMVC Hello world</title>
Message from Spring "${message}"

Spring Configuration

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean name="/hello.htm" class="com.techartifact.example.springmvc.controller.HelloController">
        <property name="message" value="This is sample message"/>

    <bean id="viewResolver"
        <property name="prefix">
        <property name="suffix">

 Web descriptor

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

    <display-name>Spring MVC example</display-name>





Run example

Download full example code from here spring-webmvc-example

Go to project directory [spring-webmvc-example] in command shell and run following command using maven

mvn clean package
mvn -Pcargo-run

You should see following output in your browser


Fall back to system properties with Spring framework

Spring allows to you, to fall-back on system properties, if you not added any corresponding values with that.
That is really a cool feature. If you need to look up,some system properties , you don’t need to do any thing
just configure your bean and Spring will take care that.

These are the some of SYSTEM_PROPTTIRES that you set in your bean


SYSTEM_PROPERTIES_MODE_FALLBACK       Check system properties if not resolvable in the specified properties.
SYSTEM_PROPERTIES_MODE_NEVER          Never check system properties.
SYSTEM_PROPERTIES_MODE_OVERRIDE       Check system properties first, before trying the specified properties.

see here for more information PropertyPlaceholderConfigurer

Spring LDAP 1.3.0.RELEASE

Spring LDAP 1.3.0.RELEASE

This is a major release, containing more than 50 fixes compared to the 1.2.1 version; modifications varying in importance from internal modifications and minor fixes to important bug fixes and and significant functionality additions.

Most importantly we now provide a means to perform simple LDAP authentication directly in LdapTemplate. Other useful improvements include TLS connection support, referral handling improvements, as well as a couple of important fixes working around problems in the underlying Java JNDI API.