在bean的內部引用另外一個bean對象:java
使用ref標籤對其進行引用: <ref bean="viewResolver2"/>web
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/" /> <property name="suffix" value=".jsp" /> <property name="order" value="2"/> </bean>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="viewResolvers"> <list> <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"/> <!-- 引用外部id爲viewResolver的bean --> <ref bean="viewResolver"/> </list> </property> </bean>
ref屬性:用來給一個對象的屬性設置值
使用<ref bean="viewResolver"/> bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- 在spring框架加載時建立 --> <bean id="borrowDao" class="dao.impl.BorrowDao" primary="true" lazy-init="true"> <property name="sessionFactory" ref="sessionFactory"></property> </bean>