Prefix mvc for element mvc:annotation-driven is not bound

If you are planning to use <mvc:annotation-driven>  into your Spring MVC application, chances that you may be facing issue for "Prefix mvc for element mvc:annotation-driven is notbound " erorr. Root cause is that your bean definition XML doesn't have names-spaces mentioned below.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">



    <context:component-scan base-package="com.anuj.spring.controller" />
    <mvc:annotation-driven />

Benefits of mvc-annotation-driven :
  • enable MVC java Config. To do same in Code instead of beans xml, you can add the annotation @EnableWebMvc to one of your @Configuration
  • enable support for formatting using @NumberFormat and @DateTimeFormat
  • enable support for validation using @Valid if JSR-303 provider present on classpath
  • HttpMessageConverter support for @RequestBody method parameters and @ResponseBody method return values from @RequestMapping or @ExceptionHandler methods. Also enable support for atom,rss,json,jaxb,String,resource,form,source convertors.
  • many more..

No comments:

Post a Comment