I'm having a strange issue with annotated controllers and Spring MVC. I was trying to use Annotated controllers for the sample MVC application that Spring ships with its documentation. I used 2.5 version.
When I specify @RequestMapping at type level, I get "HTTP ERROR: 500 No adapter for handler [Controller class name]: Does your handler implement a supported interface like Controller?
If I include it in the method level, it works fine with out an issue. Adding or removing the default handle adapters to context files made no difference:
Finally, I resorted to having @RequestMapping at controller level, as well as one at the Method level, and it worked. Anyone know what could be the issue?
Here is the sample code:
This did not work:
@Controller
@RequestMapping("/*")
public class InventoryController {
protected final Log logger = LogFactory.getLog(getClass());
@Autowired
private ProductManager productManager;
public ModelAndView inventoryHandler() {
String now = (new java.util.Date()).toString();
logger.info("returning hello view with " + now);
Map<String, Object> myModel = new HashMap<String, Object>();
myModel.put("now", now);
myModel.put("products", this.productManager.getProducts());
return new ModelAndView("hello", "model", myModel);
}
}
This worked:
@Controller
public class InventoryController {
protected final Log logger = LogFactory.getLog(getClass());
@Autowired
private ProductManager productManager;
@RequestMapping("/hello.htm")
public ModelAndView inventoryHandler() {
String now = (new java.util.Date()).toString();
logger.info("returning hello view with " + now);
Map<String, Object> myModel = new HashMap<String, Object>();
myModel.put("now", now);
myModel.put("products", this.productManager.getProducts());
return new ModelAndView("hello", "model", myModel);
}
}
This also worked:
@Controller
@RequestMapping("/*")
public class InventoryController {
protected final Log logger = LogFactory.getLog(getClass());
@Autowired
private ProductManager productManager;
@RequestMapping( method = RequestMethod.GET, value = "/hello.htm" )
public ModelAndView inventoryHandler() {
String now = (new java.util.Date()).toString();
logger.info("returning hello view with " + now);
Map<String, Object> myModel = new HashMap<String, Object>();
myModel.put("now", now);
myModel.put("products", this.productManager.getProducts());
return new ModelAndView("hello", "model", myModel);
}
}
Any ideas, what's happening here? I did a lot of search and no solution. I also tried with 2.5.6, and the issue was similar.