与元素类型 "bean" 相关联的属性 "p:host-name" 的前缀 "p" 未绑定

    //spring的配置文件applicationContext.xml中:
    <bean id="connectionFactory" 
    class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
        p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}"
        p:pool-config-ref="poolConfig" />

报错信息:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 102 in XML document from class path resource [springMVC.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 102; columnNumber: 36; 与元素类型 "bean" 相关联的属性 "p:host-name" 的前缀 "p" 未绑定。

原因:

使用<property>元素为Bean的属性装配值和引用并不太复杂。尽管如此,Spring的命名空间p提供了另一种Bean属性的装配方式,该方式不需要配置如此多的尖括号。

命名空间p的schemaURI为:

http://www.springframework.org/schema/p

如果你想使用命名空间p,只需要在Spring的XML配置中增加如下一段声明:

<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"//加上这句话
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-3.0.xsd">

通过此声明,我们现在可以使用p:作为<bean>元素所有属性的前缀来装配Bean的属性。为了示范,我们重新声明了kennyBean的配置:

<beanid="kenny"class="com.springinaction.springidol.Instrumentalist"
p:song="JingleBells"
p:instrument-ref="saxophone"/>

p:song属性的值被设置为“JingleBells”,将使用该值装配song属性。

同样,p:instrument-ref属性的值被设置为“saxophone”,将使用一个ID为saxophone的Bean引用来装配instrument属性。-ref后缀作为一个标识来告知Spring应该装配一个引用而不是字面值。

选择<property>还是命名空间p取决于你,它们是等价的。命名空间p的最主要优点是更简洁。在固定宽度的纸张上编写样例时,选择命名空间相对更合适。


参考:http://book.2cto.com/201306/25123.html

http://cache.baiducontent.com


转载于:https://my.oschina.net/anxiaole/blog/662071

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值