Spring 内部注入bean

Posted on 2018-04-12 09:50  qie_zi  阅读(106)  评论(0编辑  收藏  举报
<?xml version="1.0" encoding="UTF-8"?>

<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-3.0.xsd">

   <!-- Definition for textEditor bean using inner bean -->
   <bean id="..." class="...">
      <property name="spellChecker">
         <bean id="随意..." class="..."/>
       </property>
   </bean>

</beans>

注意,属性的name值要和方法内的属性一致,并且要注入的属性要有set方法,其实这个就是set方法注入,只不过把bean直接写在须要注入的属性标签里面