cvc-elt.1:找不到元素’beans’的声明

我试图获得一个bean对象来使用Spring Securityvalidation用户登录function:

ApplicationContext context = new ClassPathXmlApplicationContext( "com/humandevice/drive/fx/util/applicationContext.xml"); authenticationManager = (AuthenticationManager) context .getBean("authenticationManager"); 

我的applicationContext.xml如下:

                  

但我得到这个例外:

 Caused by: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 64; cvc-elt.1: Cannot find the declaration of element 'beans'. 

我很难理解这个问题。


更新


我已经对我的XML进行了一些更改:

            

我现在收到这个例外:

lineNumber: 11; columnNumber: 44; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'import'.

你的默认命名空间是http://www.springframework.org/schema/security ,你配置了xmlns:beans="http://www.springframework.org/schema/beans"这意味着你必须添加前缀beans: to所有标记formshttp://www.springframework.org/schema/beans所以您的XML应如下所示。

                  

这段代码可以帮到你。

    

对我来说,我只是在同一个地方剪切并粘贴并保存XML文件,它对我有用!!

对我来说,applicationContext.xml的更改在类路径中没有更新。 所以我从classpath中手动删除了applicationContext.xml文件,并重新构建了解决了我的问题的应用程序