package sam07;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class HelloApp {
public static void main(String[] args) { //원래는 resources 폴더에 다 가져다 놓는데 만일 다른폴더에 넣는다면 이렇게 하면된다.
ApplicationContext ac = new ClassPathXmlApplicationContext("/sam07/bean07.xml");
MessageBean mb = (MessageBean) ac.getBean("mb7");
mb.sayHello();
}
}
package sam07;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class FileOutputter implements Outputter {
private String fileName;
public void setFileName(String fileName) {
this.fileName = fileName;
}
public void output(String msg) {
System.out.println("fileName: "+fileName);
try {
FileWriter fw = new FileWriter(new File(fileName));
fw.write(msg);
fw.close();
} catch (IOException e) {
System.out.println("e.getMessage()-->"+e.getMessage());
}
}
}
package sam07;
public class MessageBeanImpl implements MessageBean {
private String name;
private String greet;
private Outputter outPutter;
public void setName(String name) {
this.name = name;
}
public void setGreet(String greet) {
this.greet = greet;
}
public void setOutPutter(Outputter outPutter) {
this.outPutter = outPutter;
}
public void sayHello() {
String msg = name + "님! " + greet;
System.out.println(msg);
if(outPutter != null) outPutter.output(msg);
}
}
정송환님! 안녕하세요
fileName: c:/log/msg1.txt