Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mvc:annotation-driven is not bound

Tags:

spring

I get this error when I run a certain Spring Web 3 project in NetBeans:

org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 30; The prefix "mvc" for element "mvc:annotation-driven" is not bound.

Here's dispatcher-servlet.xml:

<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <mvc:annotation-driven />
    <context:component-scan base-package="net.myproject.controllers"/>

    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />

</beans>

I think I did the appropriate namespace declarations, but obviously I'm still overlooking something. Why am I getting this error?

like image 761
Pieter Avatar asked May 14 '11 11:05

Pieter


People also ask

What is mvc annotation-driven?

mvc:annotation-driven is a tag added in Spring 3.0 which does the following: Configures the Spring 3 Type ConversionService (alternative to PropertyEditors) Adds support for formatting Number fields with @NumberFormat.

What is the use of mvc annotation-driven />?

mvc:annotation-driven is used for enabling the Spring MVC components with its default configurations. If you dont include mvc:annotation-driven also your MVC application would work if you have used the context:component-scan for creating the beans or defined the beans in your XML file.


Video Answer


2 Answers

This is an IDE Error, Which can be resolved by following to

xmlns:mvc="http://www.springframework.org/schema/mvc"

enter image description here

like image 143
jaipster Avatar answered Sep 17 '22 13:09

jaipster


try this it worked for me:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.mkyong.common.controller" />
<mvc:annotation-driven />

like image 32
Ahmed Avatar answered Sep 20 '22 13:09

Ahmed