【问题标题】:Errors in Spring STS servlet-context.xml fileSpring STS servlet-context.xml 文件中的错误
【发布时间】:2012-12-20 05:21:22
【问题描述】:

我是 java 和 spring 的新手。 STS 版本是 3.1.0.RELEASE。

我在“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> 

有人可以指导我做错了什么以及如何纠正它。

【问题讨论】:

  • 可以分享整个xml文件吗
  • @Arun P Johny!它是完整的 servlet-context.xml 文件

标签: xml spring spring-mvc


【解决方案1】:

您必须在 bean 元素前面加上 beans:

例如:

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

这是因为您导入了带有namespace beansbean 元素。

【讨论】:

    【解决方案2】:
    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-16
      • 2013-01-17
      • 2017-03-21
      • 1970-01-01
      • 2014-07-03
      • 2013-12-30
      • 2016-09-21
      相关资源
      最近更新 更多