GetSum.java
package com.test.diEx01;
public class GetSum {
private int aa;
private int bb;
public int getAa() {
return aa;
}
// public void setAa(int aa) {
// this.aa = aa;
// }
//
// public int getBb() {
// return bb;
// }
public void setBb(int bb) {
this.bb = bb;
}
public void sum(int aa, int bb){
System.out.println("더하기");
int result = aa + bb;
System.out.println("합: "+result);
}
}
MyGetSum.java
package com.test.diEx01;
public class MyGetSum {
public GetSum getsum;
private int a;
private int b;
public MyGetSum(){
}
public void sum(){
getsum.sum(a, b);
}
public void setGetsum(GetSum getsum) {
this.getsum = getsum;
}
public void setA(int a) {
this.a = a;
}
public void setB(int b) {
this.b = b;
}
}
Main.java
package com.test.diEx01;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
public class Main {
public static void main(String[] args) {
// MyGetSum myGetSum = new MyGetSum();
// myGetSum.setGetsum(new GetSum());
//
// myGetSum.setA(10);
// myGetSum.setB(100);
AbstractApplicationContext ctx = new GenericXmlApplicationContext("classpath:getsum.xml");
MyGetSum myGetSum = ctx.getBean("myGetSum", MyGetSum.class);
myGetSum.sum();
}
}
'기존카테고리 > Spring_basic1' 카테고리의 다른 글
DI - 프로퍼티(property) 방식 (0) | 2017.07.10 |
---|---|
DI - Constructor(생성자)를 통한 주입 예제2 (0) | 2017.07.10 |
DI - Constructor(생성자)를 통한 주입 (0) | 2017.07.10 |
DI 실습1 (0) | 2017.07.09 |
스프링 개요 (0) | 2017.07.09 |