@Autowired
애너테이션은 빈을 자동으로 연결하는 기능입니다.
@Autowired
는 생성자, 메서드, 필드
수준에서 사용할 수 있습니다.
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class SpringTestServiceImpl implements SpringTestService { @Autowired private SpringTestDao springTestDao; }
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class SpringTestServiceImpl implements SpringTestService { private SpringTestDao springTestDao; @Autowired public void obtainSpringTestDao (SpringTestDao springTestDao) { this.springTestDao = springTestDao; } }
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class SpringTestServiceImpl implements SpringTestService { private SpringTestDao springTestDao; @Autowired public SpringTestServiceImpl (SpringTestDao springTestDao) { this.springTestDao = springTestDao; } }
필드, 메서드, 생성자에 설정하면, AutowiredAnnotationBeanPostProcessor
를 통해 자동 연결을 수행합니다.