\
개발환경
스프링 버전 : Spring Tool Suite 3.9.11
JDK 1.8
톰켓 : 8.5
2021.05.17 - [분류 전체보기] - 스프링 다운로드 /STS 다운로드 (3.9.14 v 다운받기)서블릿/JDK 8 호환
2021.03.29 - [JAVA/JAVA(자바)설치 및 툴 이용(ECLIPSE)] - [JAVA] 자바 설치 및 환경 하기 JDK 1.8 버전/ 8버전
package ex01.di.annot;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainEntry {
public static void main(String[] args) {
ApplicationContext ctx =
new ClassPathXmlApplicationContext("ex01/di/annot/appCtx.xml");
MonitorViewer viewer = ctx.getBean("m", MonitorViewer.class);
//viewer.getRecorder();
//viewer.recorderMethodPrint();
}
}
package ex01.di.annot;
import org.springframework.beans.factory.annotation.Autowired;
public class MonitorViewer {
//@Autowired // 1. 멤버필드에 설정 가능
private Recorder recorder; //멤버변수
@Autowired // 2. setter method 설정 가능
public void setRecorder(Recorder recorder) { // DI
this.recorder = recorder;
System.out.println("222 setter method success!!");
}
// 3. 생성자 함수에 설정 가능
//@Autowired // 4. 일반 메소드에 설정 가능
public void recorderMethod(Recorder recorder) {
this.recorder = recorder;
System.out.println("recorderMethod() autowired");
}
public Recorder getRecorder() {
System.out.println("getRecorder() call~~");
return recorder;
}
public void recorderMethodPrint() {
System.out.println("method 주입 : " + this.recorder);
}
}
appCtx.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.3.xsd">
<!-- appCtx.xml -->
<context:annotation-config />
<!-- <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> -->
<bean class="ex01.di.annot.Recorder" id="r1" />
<bean class="ex01.di.annot.MonitorViewer" id="monitorViewer" name="m, m2" />
</beans>
2021.05.26 - [[Spring] 스프링 프래임워크] - [스프링]Spring //@Autowired / 어노테이션 방식
[스프링] Spring AOP - 개요 , 개념 설명 (0) | 2021.05.26 |
---|---|
[스프링] @Configuration/ @Scope / 기존 코드 @Configuration 사용 한 코드 (0) | 2021.05.26 |
[스프링]Spring //@Autowired / 어노테이션 방식 (0) | 2021.05.26 |
[Spring] 스프링 MVC //개요생명주기 //Controller 계층 구조 (0) | 2021.05.24 |
[스프링]Spring /web.xml 구조 (0) | 2021.05.24 |