spring-210724-03–IOC容器–Bean管理XML方式-p名称空间注入
使用p名称空间注入,可以简化基于xml配置方式
在beams约束中添加:
xmlns:p="http://www.springframework.org/schema/p"
testP.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<bean id="book" class="com.bgy.spring.Book" p:bname="数据结构" p:bauthor="严蔚敏">
</bean>
</beans>
本文介绍如何使用Spring框架的p名称空间来简化XML配置文件中的Bean属性注入过程。通过示例展示了如何利用p名称空间为Book类注入属性,提高了配置文件的简洁性和可读性。

被折叠的 条评论
为什么被折叠?



