Cannot find the declaration of element 'beans'

后端 未结 10 1634
忘掉有多难
忘掉有多难 2020-11-30 01:59

I have the spring jars of spring-3.2.0.RC1.jar and trying to implement Apache ActiveMQ helloWorld program from tutorial given here. Th

相关标签:
10条回答
  • 2020-11-30 02:18

    This error of Cannot find the declaration of element 'beans' but for a whole different reason

    It turs out my internet connection was not very reliable, so i decided to check first for this url

    http://www.springframework.org/schema/context/spring-context-4.0.xsd

    Once I saw that the xsd was open succesfully I clean the Eclipse(IDE) project and the error was gone

    If you try this steps and still get the error then check the Spring version so that it matches as mentioned by another answer

    <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-**[MAYOR.MINOR]**.xsd">
    

    Replace [MAYOR.MINOR] on the last line with whatever major.minor Spring version that you are using

    For Spring 4.0 http://www.springframework.org/schema/context/spring-context-4.0.xsd

    For Sprint 3.1 http://www.springframework.org/schema/beans spring-beans-3.1.xsd

    All the contexts are available here http://www.springframework.org/schema/context/

    0 讨论(0)
  • 2020-11-30 02:28

    Use this to solve your problem:

    <context:annotation-config/>
    
    0 讨论(0)
  • 2020-11-30 02:29

    Try this, assuming you're on Spring 3.1:

    <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-3.1.xsd">
    

    Replace 3.1 on the last line with whatever major Spring version you use. Meaning: there is no 3.1.1 XSD even though there is a Spring version 3.1.1.

    0 讨论(0)
  • 2020-11-30 02:29

    I had this issue and the root cause turned out to be white-space (shown as dots below) after the www.springframework.org/schema/beans reference in xsi:schemaLocation, i.e.

    <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"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans....
    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
    
    0 讨论(0)
  • 2020-11-30 02:29

    For me the problem was that spring was not able to download http://www.springframework.org/schema/beans/spring-beans.xsd or http://www.springframework.org/schema/context/spring-context.xsd

    However I was able to access those from my browser as it was using my machines proxy. So I just copied the content of the two xsds to files named spring-beans.xsd and spring-context.xsd and replaced the http url with the file names and it worked for me.

    0 讨论(0)
  • 2020-11-30 02:30

    Make sure if all the spring jar file's version in your build path and the version mentioned in the xml file are same.

    0 讨论(0)
提交回复
热议问题