자바과정/스프링
스프링 namespace : c와 p 사용
Parkej
2021. 4. 5. 17:10
쓰기전 네임스페이스 체크
applicationCTX.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:c="http://www.springframework.org/schema/c"
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="studentInfo1" class="com.javalec.ex.StudentInfo">
<property name="student">
<ref bean="student1"></ref>
</property>
</bean>
<bean id="student1" class="com.javalec.ex.Student" c:name="홍길동"
c:age="20">
<!-- <constructor-arg> <value>홍길동</value> </constructor-arg> <constructor-arg>
<value>19</value> </constructor-arg> -->
<constructor-arg>
<list>
<value>수영</value>
<value>요리</value>
</list>
</constructor-arg>
</bean>
<bean id="student3" class="com.javalec.ex.Student" c:name="홍길자"
c:age="30">
<!-- <constructor-arg> <value>홍길자</value> </constructor-arg> <constructor-arg>
<value>30</value> </constructor-arg> -->
<constructor-arg>
<list>
<value>히히</value>
<value>하하</value>
</list>
</constructor-arg>
</bean>
</beans>
applicationCTX.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:c="http://www.springframework.org/schema/c"
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="family" class="com.javalec.ex.Family" c:papaName="홍아빠"
c:mamiName="홍엄마" p:sisterName="홍누나" p:brotherName="홍오빠">
<!-- <constructor-arg> <value>홍아빠</value> </constructor-arg> <constructor-arg>
<value>홍엄마</value> </constructor-arg> <property name="sisterName" value="홍누나"/>
<property name="brotherName" value="홍오빠"/> -->
</bean>
</beans>
반응형