<bean id = "아이디" class = "패키지명.클래스명" scope = "singleton"/>
<bean id = "아이디" class = "패키지명.클래스명" scope = "singleton">
<constructor-arg ref"의존성주입받을 객체"/>
</bean>
1. 의존성 주입할 클래스 설정
<bean id="od" class="day0618.OracleDAO" scope="singleton"/>
2. 의존성 주입 받을 클래스를 설정하고 <constructor-arg ref=""/> 속성 정의
<bean id = "service" class = "day0618.ServiceImpl" scope = "singleton">
<constructor-arg ref="od"/>
</bean>
3. Spring Container에서 얻기
Service s = ac.getBean("service");의존성 주입할 클래스 설정
<bean id = "아이디" class = "패키지명.클래스명" scope = "singleton"/>

의존성 주입 받을 클래스를 설정하고 <property name="" ref=""/> 속성 정의
<bean id = "아이디" class = "패키지명.클래스명" scope = "singleton">
<property name="setter method명" ref="의존성 주입할 객체"/>
</bean>
// setter method명 : set을 제외한 method명을 소문자로 작성
1. 의존성 주입받을 클래스 설정
public class ServiceImpl{
private DAO dao;
public SerivceImpl(){
}
public void setDao(DAO dao){
this.dao=dao;
}
}
<bean id = "od" class = "day0618.OracleDAO" scope = "singleton"/>
<bean id = "service" class = "day0618.ServiceImpl" scope = "singleton">
<property name="dao" ref="od"/>
</bean>
singleton pattern으로 구현된 클래스를 객체화
<bean factory-method="method명">
singleton pattern이 적용된 클래스
public class ServiceImpl{
private static ServiceImpl si;
private ServiceImpl(){
}
public static ServiceImpl getInstance(){
return si;
}
}
private 접근지정자가 설정된 생성자도 호출 가능.
<bean id = "아이디" class="패키지명.클래스명"/>
factory-method 호출
<bean id = "아이디" class="패키지명.클래스명"> factory-method="getInstance"/>
- getnInstance method가 생성하여 반환한 객체를 id로 저장하여 사용한다.
생성자가 객체가 아닌 다른 데이터 형을 정의하고 있을 때
정수의 Injection : value속성( value="값" )과 type속성 (type="데이터형")으로 사용.
사용법 )
<bean id="" class="">
<constructor-arg value="값" type="데이터형"/>
</bean>
public class TestService{
private String str;
private int value;
public TestService(int value){
this.value=value;
}
public TestService(String str){
this.str=str;
}
}
type속성을 기술하지 않으면 문자열로 매개변수를 받음
<bean id="ts" class="TestService">
<constructor-arg value="2024"/>
</bean>
정수를 injection 하려면 type속성을 기술
<bean id="ts" class="TestService">
<constructor-arg value="2024" type="int"/>
</bean>
public class Service{
private List<String> list;
public Service(List<String> list){
this.list=list;
}
}
<bean id="" class="">
<constructor-arg>
<list> 또는 <set>
<value type="데이터형"> 값 </value>
<value type="데이터형"> 값 </value>
</list> 또는 </set>
</constructor-arg>
</bean>
public class Service{
private Map<String,String> map;
public Service(Map<String,String> map){
this.map=map;
}
}
<bean id="" class="">
<constructor-arg>
<map>
<entry>
<key><value type="데이터형">값</value></key>
<value type="데이터형"> 값 </value>
</entry>
.
.
</map>
</constructor-arg>
</bean>

@Component
public class Test{
@Autowired(required = false)
private Temp temp;
}@Component
public class Test{
private Temp temp;
@Autowired(required =false)
private Temp temp(Temp temp){
this.temp = temp
}
}@Component
public class Test{
private Temp temp;
@Autowired(required =false)
private void setTemp(Temp temp){
this.temp = temp
}
}