我是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>
答案 0 :(得分: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>
答案 1 :(得分: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/