no declaration can be found for element 'context:annotation-config'
Asked Answered
I

5

29

in spring whenever i write <context:annotation-config/> in my spring.xml i get this error:-

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 81 in XML document from class path resource [spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 81; columnNumber: 30; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'.

And the content of my spring.xml is

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
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-4.0.xsd"
xmlns:context="http://www.springframework.org/schema/context"
>

<bean id="circle" class="com.mysite.Circle">
</bean>

 ...

<context:annotation-config/>

Would anyone please tell me where am i going wrong ????

Intracardiac answered 14/9, 2013 at 14:52 Comment(1)
Possible Duplicate #6058537Tourneur
S
49

You are using an XML namespace (in this case context) without declaring it

Change your xml to this:

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

You were also referencing http://www.springframework.org/schema/beans/spring-beans-4.0.xsd, which I don't think exists.

Spay answered 14/9, 2013 at 17:34 Comment(1)
This worked for me. But can someone please explain me exactly what the error was and how these namespace resolve it. In previous declaration also we defined xmlns:context="springframework.org/schema/context".Cumquat
H
5

Take attention: when you use context namespace, you should update in XML head 2 attributes:

  • xmlns:context
  • xsi:schemaLocation.

Beginners used to add only xmlns:context and forget about 2 new entries to xsi:schemaLocation:

<beans xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                    http://www.springframework.org/schema/context 
                    http://www.springframework.org/schema/context/spring-context-4.0.xsd"
......
>
Heat answered 31/1, 2016 at 23:41 Comment(0)
S
4

If using Spring 4.0, here's what I found:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
   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-4.0.xsd  
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-4.0.xsd" 
   xmlns:context="http://www.springframework.org/schema/context">

It worked for me. Found the reference here: http://javahash.com/spring-4-mvc-hello-world-tutorial-full-example/

Secundas answered 7/7, 2015 at 9:45 Comment(1)
how about context for version 5.2Hangchow
H
0

Add these lines in your xml file.

<xmlns:context="http://www.springframework.org/schema/context"

And

<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">

.

Halfblooded answered 5/1, 2018 at 14:46 Comment(0)
H
0

finally got solution just add this contain in XML file

<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
</bean>
Hesione answered 2/11, 2023 at 20:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.