https://www.youtube.com/playlist?list=PLq8wAnVUcTFUHYMzoV2RoFoY2HDTKru3T
스프링 강의를 듣고 정리한 내용입니다
Program 클래스
▷ exam을 참조하는 ArrayList 생성
//List<Exam> exams = new ArrayList<>();
List<Exam> exams = (List<Exam>) context.getBean("exams");
exams.add(new NewlecExam(1, 1, 1, 1));
for(Exam e : exams) System.out.println(e);
▷ xml에서 ArrayList 생성하기
<bean class="java.util.ArrayList" />
Program 클래스에서
exams.add(new NewlecExam(1, 1, 1, 1)); 코드를 xml로 변환하는 방법
▷ setting.xml 수정
<bean class="java.util.ArrayList">
<constructor-arg>
<list>
<bean class="spring.di.entity.newlecExam" p:kor="1" p:eng="1"/>
<!-- 객체를 참조하여 추가 -->
<ref bean="exam"/>
</list>
</constructor-arg>
</bean>
Collection을 개별적으로 만드는 방법(생성자 이용 x)
-> namespace를 추가해야 한다
beans에
xmlns:util="http://www.springframework.org/schema/util"
코드를 추가한다
▷ setting.xml 추가
<util:list>
<bean class="spring.di.entity.newlecExam" p:kor="1" p:eng="1"/>
</util:list>
-> 실제로 객체를 만들 수 있다
List의 클래스를 ArrayList로 지정하여 구체화 시킨다
<util:list list-class="java.util.ArrayList">
<bean class="spring.di.entity.newlecExam" p:kor="1" p:eng="1"/>
</util:list>
'백엔드 > Spring' 카테고리의 다른 글
Spring - @Autowired의 참조 기준 | TIL_155 (0) | 2022.10.22 |
---|---|
Spring - 어노테이션의 장점 | TIL_154 (0) | 2022.10.20 |
Spring - 생성자 DI | TIL_152 (0) | 2022.10.12 |
Spring - 값 형식 DI | TIL_151 (0) | 2022.10.10 |
Spring - IoC 컨테이너(ApplicationContext) | TIL_150 (0) | 2022.10.06 |