【问题标题】:Attribute p:prefix not allowed here属性 p:prefix 不允许在这里
【发布时间】:2013-12-15 17:58:05
【问题描述】:

我用 spring mvc 在我的dispatcherServlet.xml 文件中创建了一个项目

<bean id="jspViewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/views/"
          p:suffix=".jsp"
            />

p:prefixp:suffix 是不允许的。我该如何解决这个问题?我用过 SpringVersion 3.2.3.RELEASE

【问题讨论】:

  • 你如何解决你的问题?

标签: xml spring spring-mvc


【解决方案1】:

您需要添加 p-namespace 声明:xmlns:p="http://www.springframework.org/schema/p"

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

参见 Spring 参考:Chapter 5.4.2.6 XML shortcut with the p-namespace

【讨论】:

【解决方案2】:

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

【讨论】:

  • 您应该解释您的答案如何解决问题,即您需要将 spring 框架命名空间添加到 xml beans 定义文件的顶部。特别是您需要的部分是xmlns:p="http://www.springframework.org/schema/p"。请注意,没有什么要求您使用 p:。这些只是按惯例使用。您可以重写您的 XML 以在任何地方使用 a: - 只要它们被定义为映射到相同的 XML 名称空间。 (这就是为什么需要定义它们。)
猜你喜欢
  • 2021-09-12
  • 1970-01-01
  • 1970-01-01
  • 2014-05-23
  • 1970-01-01
  • 1970-01-01
  • 2017-06-05
  • 2015-09-14
  • 1970-01-01
相关资源
最近更新 更多