Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring模板应用程序中的bean:tag是什么?_Java_Xml_Spring_Spring Mvc - Fatal编程技术网

Java Spring模板应用程序中的bean:tag是什么?

Java Spring模板应用程序中的bean:tag是什么?,java,xml,spring,spring-mvc,Java,Xml,Spring,Spring Mvc,我刚刚使用Spring源IDE创建了一个Spring模板应用程序,它在servlet-context.xml中定义了ViewResolver,如下所示: <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/views/" /> <beans

我刚刚使用Spring源IDE创建了一个Spring模板应用程序,它在servlet-context.xml中定义了ViewResolver,如下所示:

<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>

我不熟悉这种配置,我通常看到ViewResolver是这样定义的:

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>


有人能解释这两者的区别吗?

它们实际上是等价的。在第一种情况下,
bean
是springbean的名称空间前缀。模式定义中的名称空间前缀到名称空间的映射在别处完成——最有可能在根元素中完成

在第二种情况下,不需要前缀,因为默认名称空间映射到相同的模式——同样,很可能是在根元素中。从文件中:

<beans xmlns="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.xsd">
因此,它实际上只是一个XML的东西,而不是Spring的东西

<xsd:schema xmlns="http://www.springframework.org/schema/beans" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.springframework.org/schema/beans">