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

后端 未结 4 1718
伪装坚强ぢ
伪装坚强ぢ 2021-02-05 04:07

in spring whenever i write in my spring.xml i get this error:-

Exception in thread \"main\" org.springfram

相关标签:
4条回答
  • 2021-02-05 04:17

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

    .

    0 讨论(0)
  • 2021-02-05 04:24

    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/

    0 讨论(0)
  • 2021-02-05 04:25

    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.

    0 讨论(0)
  • 2021-02-05 04:35

    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"
    ......
    >
    
    0 讨论(0)
提交回复
热议问题