Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- react
- 빈
- spring
- 인터페이스
- DI
- 스프링 컨테이너
- github
- java
- mysql
- 어노테이션
- springboot
- 트랜잭션
- 스프링
- 자바
- 자동주입
- 깃허브
- 이클립스
- pom.xml
- Spring 개발환경 설정
- JVM
- Spring legacy Project
- 영속성 컨텍스트
- 의존성주입
- @Bean
- @transactional
- 리액트
- list
- 객체
- 상속
- merge
Archives
- Today
- Total
DEVLOG
다양한 의존 객체 주입 방법 본문
1. 생성자를 이용한 의존 객체 주입
public StudentRegisterService(StudentDao studentDao) {
this.studentDao = studentDao;
}
↓
<bean id="studentDao" class="ems.member.dao.StudentDao"></bean> // studentDao 객체생성
<bean id="registerService" class="ems.member.service.StudentRegisterService">
<constructor-arg ref="studentDao"> </constructor-arg> // 해당 객체의 생성자는 studentDao 객체를 참조하겠다.
</bean>
2. setter를 이용한 의존 객체 주입
public void setUserId(String userId){
this.userId = userId;
}
public void setUserPw(String userPw){
this.userPw = userPw;
}
↓ set떼고 첫글자 대문자 -> 소문자
<bean id = "detailBaseConnectionInfoDev" class="ems.member.DatabaseConnectionInfo">
<property name="userId" value="scott" />
<property name="userPw" value="tiger" />
</bean>
3. List타입 의존 객체 주입
public void setDevelopers(List<String> developers) {
this.developers = developers;
}
↓
<property name="developers">
<list>
<value>Cheney.</value>
<value>Eloy.</value>
<value>Jasper.</value>
<value>Dillon.</value>
<value>Kian.</value>
</list>
</property>
4. Map타입 의존 객체 주입
public void setAdminstrators(Map<String, String> adminstrators){
this.adminstrators = adminstrators;
}
↓
<property name="adminstrators">
<map>
<entry>
<key>
<value>Cheney</value>
</key>
<value>cheney@stringPjt.org</value>
</entry>
</map>
</property>
출처
자바 스프링 프레임워크(renew ver.) - 신입 프로그래머를 위한 강좌 - 인프런 | 강의
스프링 프레임워크 기본부터 실전 사용법까지! 충실하고 폭넓은 설명과 예제를 통해 현장에 바로 투입되어 활약하는 개발자로 거듭나세요., - 강의 소개 | 인프런...
www.inflearn.com
'Spring' 카테고리의 다른 글
의존객체 자동 주입 (0) | 2022.06.07 |
---|---|
스프링 설정 파일 분리 (0) | 2022.06.06 |
DI(Dependency Injection) : 의존성 주입 (0) | 2022.06.04 |
스프링 프로젝트 생성(2) - 작업 폴더를 생성하여 프로젝트 import하기 (0) | 2022.06.04 |
스프링 프로젝트 생성(1) (0) | 2022.06.03 |
Comments