<constructor-arg name="" value=""/><constructor-arg name="" ref=""/><property name="존재하는 세터함수 뒷부분 이름(대부분 멤버변수명)(xxx)" value="값"></property><property name="xxx"><value>값</value</property> <bean class="com.spring.EchoBean" id="echoBean">
<property name="xxx" ref="anotherBean"></property>
</bean>
<bean class="com.spring.EchoBean" id="echoBean2">
<property name="xxx">
<ref bean="anotherBean2"></ref>
</property>
</bean>
xml파일 -> namespace로 가서 -> p 체크후 저장
그럼 이제 p:태그를 사용할 수 있다.
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/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- namespace: p 설정 -->
<bean class="com.sprnig.Cat" id="cat" p:catName="야옹이" p:catAge="10"></bean>
<bean class="com.sprnig.Person" id="person" p:username="홍길동" p:age="20" p:cat-ref="cat"></bean>
</beans>
constructor-arg나 property 태그의 내부에 list태그를 이용하여 생성이 가능하다.
<bean class="com.spring.EchoBean" id="echoBean">
<constructor-arg name="valueList">
<!-- list 주입 -->
<list>
<value>10</value>
<value>20</value>
<value>30</value>
</list>
</constructor-arg>
</bean>
<bean class="com.spring.AnotherBean" id="anotherBean1">
<property name="name" value="test1"></property>
</bean>
<bean class="com.spring.AnotherBean" id="anotherBean2">
<property name="name" value="test2"></property>
</bean>
<bean class="com.spring.AnotherBean" id="anotherBean3">
<property name="name" value="test3"></property>
</bean>
<bean class="com.spring.EchoBean" id="echoBean">
<constructor-arg name="anotherBean" ref="anotherBean1"></constructor-arg>
<property name="valueList">
<list>
<ref bean="anotherBean1"/>
<ref bean="anotherBean2"/>
<ref bean="anotherBean3"/>
</list>
</property>
</bean>
namespace에서 util 체크후 사용 가능
리스트를 외부에서 만들고 id를 부여하여 여러곳에서 사용이 가능
<bean class="com.spring.AnotherBean" id="anotherBean1">
<property name="name" value="test1"></property>
</bean>
<bean class="com.spring.AnotherBean" id="anotherBean2">
<property name="name" value="test2"></property>
</bean>
<bean class="com.spring.AnotherBean" id="anotherBean3">
<property name="name" value="test3"></property>
</bean>
<util:list id="list">
<ref bean="anotherBean1"/>
<ref bean="anotherBean2"/>
<ref bean="anotherBean3"/>
</util:list>
<bean class="com.spring.EchoBean" id="echoBean">
<constructor-arg name="anotherBean" ref="anotherBean1"></constructor-arg>
<property name="valueList" ref="list"></property>
</bean>
<property name="mapCat">
<map>
<entry key="one" value-ref="pet01"></entry>
<entry key="two">
<ref bean="pet02"></ref>
</entry>
</map>
</property>