반응형

Data.java


package message;

public class Data {
	private String name;
	private int num;

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Data [name=" + name + ", num=" + num + "]";
	}


}


Main.java


package message;

import org.springframework.context.support.GenericXmlApplicationContext;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		GenericXmlApplicationContext context = new GenericXmlApplicationContext(
				"message/applicationContext.xml");

		MessageBean mb = context.getBean("insa", MessageBeanEn.class);
		mb.greeting("키키키");

		String str = context.getBean("str", String.class);
		System.out.println("Str: " + str);
		
		Data data = context.getBean("data",Data.class);
		
		data.setName("으악으각");
		
		System.out.println("데이터: "+data);

	}

}


MessageBean.java


package message;

public interface MessageBean {
	public void greeting(String name);
}


MessageBeanEn.java


package message;

public class MessageBeanEn implements MessageBean{

	@Override
	public void greeting(String name) {
		// TODO Auto-generated method stub
		System.out.println("Hello ~ " + name);
		
	}

}



MessageBeanKr.java


package message;

public class MessageBeanKr implements MessageBean{

	@Override
	public void greeting(String name) {
		// TODO Auto-generated method stub
		System.out.println("안녕하세요~ "+name+"님");
		
	}

}


applicationContext.xml






	

	
		
			안녕안녕 키키키키킼
		
	

	
		
			이상주누주준
		
		
			123123
		

	




20141015_Spring_message.zip

'JAVA > Spring' 카테고리의 다른 글

[Spring] MCV  (0) 2014.11.18
[Spring] AOP  (0) 2014.11.18
[Spring] Message  (0) 2014.11.18
[Spring] DI oracle (데이터베이스 접속하기)  (0) 2014.11.18
[spring] 팩토리 클래스 찾아서 메서드 호출하기( IOC )  (0) 2014.11.18

+ Recent posts