Monday, July 12, 2010

Spring3 and the departure from CoC

Almost two years have passed since I documented a simple way to get Convention Over Configuration (CoC) while using Spring.

Since then I built a nice Framework where developers could just concentrate on implementing Controller logic, reusable services and DAOs.

A new project has come to my plate and a new team eager to use the latest from Spring (Spring 3). I would love to be wrong but Spring3 is favoring the use of annotations for URL/Controller Mapping and my simple GreetingController will not longer work with ControllerClassNameHandlerMapping

So now my Controller will need to repeat himself === not agile (Note I tested this with the Spring3 Petclinic example):

package org.springframework.samples.petclinic.web;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.stereotype.Controller;


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

public class GreetingController {

public ModelAndView hi(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
ModelAndView mav = new ModelAndView("messageView");
mav.addObject("message", "Hi");
return mav;

public ModelAndView hello(HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView mav = new ModelAndView("messageView");
mav.addObject("message", "Hello");
return mav;

IMHO if it says it is a controller and it has public methods that should be enough so it is missing a default (and very useful) implementation. If it walks like a duck it must be then a duck.


Marlus said...

But the documentation still brings the CoC as an option, wierd...

Nestor Urquiza said...

I have posted in Spring3 forums the question ( )

The suggested CoC from your link is not taking into consideration MultiActioController and in a real CoC approach you should support them as REST is still not preferred by some teams (I include myself there) for a simple reason: Browsers still do not support the 4 verbs and then you need to tweak DELETE/PUT actions.