0

我是 Spring 3 的新手。我不知道如何在 Spring 中修复这个命名空间错误security.xml。实际上我想在 bean 周围添加配置文件代码,所以每当我添加

<beans:beans profile="dev">

在任何 bean 周围,它都会引发以下错误: 在此行找到多个注释:-cvc-complex-type.2.4.a:发现以元素“context:component-scan”开头的无效内容。'{"http://www.springframework.org/schema/beans":beans}' 之一是预期的。- 由 org.springframework.transaction.interceptor.TransactionInterceptor.invoke(org.aopalliance.intercept.MethodInvocation) 建议

这是 .xml 的代码:

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


   <beans:beans profile="dev">  **( This is code that generates error)**
    <beans:bean id="loggerListener" class="org.springframework.security.authentication.event.LoggerListener"/>
    </beans:bean>
4

2 回答 2

0

如果我们在任何嵌套标签下方放置一个声明,我们将得到异常

看看这篇文章

http://gordondickens.com/wordpress/2012/06/12/spring-3-1-environment-profiles/

还要确保 beans 节点是文件 http://gordondickens.com/wordpress/2012/06/12/spring-3-1-environment-profiles/中的最后一个元素

于 2015-01-15T18:36:03.710 回答
0

用这个

<beans:beans xmlns="http://www.springframework.org/schema/security"
  xmlns:beans="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.0.xsd
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.1xsd">


   <beans:beans profile="dev">  
    <beans:bean id="loggerListener" class="org.springframework.security.authentication.event.LoggerListener"/>
    </beans:bean>

</beans>
于 2013-02-03T07:36:13.280 回答