2012-12-20 102 views
2

Iam新增了java和spring。 STS版本是3.1.0.RELEASE。Spring STS servlet-context.xml文件中的錯誤

Iam在「servlet-context.xml」文件中出現錯誤。

Multiple annotations found at this line: 
- Cannot locate BeanDefinitionParser for element [bean] 
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'bean'. 
- Configuration problem: Cannot locate BeanDefinitionParser for element [bean] Offending resource: file [D:/springy/roo/t03/src/main/ 
webapp/WEB-INF/spring/appServlet/servlet-context.xml] 

錯誤是在這些條目中的XML文件:

<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver" p:basename="views" /> 

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" p:definitions="/WEB-INF/tiles-defs.xml" /> 

以下是servlet的context.xml文件

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
     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.xsd"> 

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 

    <!-- Enables the Spring MVC @Controller programming model --> 
    <annotation-driven /> 

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> 
    <resources mapping="/resources/**" location="/resources/" /> 

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> 
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <beans:property name="prefix" value="/WEB-INF/views/" /> 
     <beans:property name="suffix" value=".jsp" /> 
    </beans:bean> 

    <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver" p:basename="views" /> 

    <context:component-scan base-package="org.foo.bar" /> 

    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" p:definitions="/WEB-INF/tiles-defs.xml" />  
</beans:beans> 

可有人指導我什麼蔭做錯了,以及它如何可以糾正。

+0

可以分享整個xml文件 –

+0

@Arun P Johny!它是完整的servlet-context.xml文件 – Simpanoz

回答

2

您必須將bean元素與beans:

前加前綴:

<beans:bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver" p:basename="views" /> 

這是因爲你已導入bean元素與namespacebeans

0
<beans:bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
    <beans:property name="viewClass" value= "org.springframework.web.servlet.view.tiles2.TilesView" /> 
</beans:bean> 
<beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> 
    <beans:property name="definitions" > 
     <beans:list> 
      <beans:value>/WEB-INF/tiles.xml</beans:value> 
     </beans:list> 
    </beans:property> 
</beans:bean> 
相關問題