Spring Bean标记错误

时间:2016-08-29 12:01:27

标签: spring spring-security

有些人可以告诉我这里缺少的东西。我得到以下异常

 Line 76 in XML document from file [C:\S2\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\proj_name\WEB-INF\classes\spring\test-context.xml] is invalid; nested exception is 
 org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content 
 was found starting with element 'bean'. One of '{"http://www.springframework.org/schema/beans":description, 
  "http://www.springframework.org/schema/beans":meta,            
"http://www.springframework.org/schema/beans":constructor-arg,      "http://www.springframework.org/schema/beans":property, "http://www.springframework.org/schema/beans":qualifier, "http://www.springframework.org/schema/beans":lookup-method, "http://www.springframework.org/schema/beans":replaced-method,     WC[##other:"http://www.springframework.org/schema/beans"]}' is expected.

我的test-context.xml如下所示。

<beans xmlns="http://www.springframework.org/schema/beans" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:batch="http://www.springframework.org/schema/batch"
  xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd">

<bean id="restAuthenticationEntryPoint" class="com.test.security.RestAuthenticationEntryPoint"> 

请有人告诉我为什么我在这里失踪。我有春天的3.0.5春天罐子

2 个答案:

答案 0 :(得分:1)

您遗失了<beans> </beans>个标记:

<beans>
   <bean id="restAuthenticationEntryPoint" class="com.test.security.RestAuthenticationEntryPoint">
<beans>

这是错误消息想要告诉你的内容......

  

从元素'bean'开始发现无效内容。

“此处不允许使用bean标记”

  

其中一个[..] bean,[..]是预期的

这里唯一有效的标签是“豆子”等。

答案 1 :(得分:0)

<beans:beans/>添加到您的配置xml。

<beans:beans xmlns="http://www.springframework.org/schema/beans" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:batch="http://www.springframework.org/schema/batch"
          xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd">

  <beans:beans id="restAuthenticationEntryPoint" class="com.test.security.RestAuthenticationEntryPoint"/>

</beans:beans>

在您的xml中,您已打开<bean>标记但未关闭。 <beans xmlns....> </beans>的位置和restAuthenticationEntryPoint的相同位置 所以你得到了那个例外。