Spring
[Spring] 어노테이션(annotation) 의존성 주입
sweetseonah1004
2024. 10. 4. 11:41
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan base-package="test" />
@component("apple")
== Iphone apple = new Iphone();
== <bean class="Iphone" id="apple" />
1. 대신에 @Component로 객체 new
2. DI(의존주입) 기존에는 생성자, Setter
==>>> @Autowired 로 주입
3. @Autowired 메모리의 자료형만 참고
==>>> DI 모호성 에러
갤럭시 폰 생성 DI해서 폰 생성해줘~ 라는 요청을 받는 다면
1. 대신에 @Component로 객체 new
2. DI(의존주입) 기존에는 생성자, Setter
==>>> @Autowired 로 주입
3. @Autowired 메모리의 자료형만 참고
==>>> DI 모호성 에러