spring-bean依赖注入-02(通过p命名空间注入)
生活随笔
收集整理的這篇文章主要介紹了
spring-bean依赖注入-02(通过p命名空间注入)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
上一篇博客講述了為什么使用spring依賴注入,怎么注入,詳見
spring-bean依賴注入-01(等你來點擊)
廢話不多說,開始使用p命名空間進行set注入
使用另外一種注入方式是這樣的(具體實現依賴注入-01),延續上一篇的注入配置的applicationContext.xml文件
使用p命名空間后
<?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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="userDao" class="com.hao.dao.impl.UserDaoImpl"/><bean id="userService" class="com.hao.service.impl.UserServiceImpl" p:userDao-ref="userDao"/></beans>其他具體操作詳見鏈接
總結
以上是生活随笔為你收集整理的spring-bean依赖注入-02(通过p命名空间注入)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring-Bean的依赖注入分析-0
- 下一篇: spring-bean依赖注入-03