MessageBean Interface (MesageBean.java)
package sample; public interface MessageBean { void sayHello(String name); }MessageBeanEn Class (MessageBeanEn.java)
package sample; public class MessageBeanEn implements MessageBean{ @Override public void sayHello(String name){ System.out.println("Hello," + name + "!"); } }MessageBeanKo Class (MessageBeanKo.java)
package sample; public class MessageBeanKo implements MessageBean{ @Override public void sayHello(String name){ System.out.println("안녕하세요!" + name + "씨"); } }HelloApp Class (HelloApp.java - Application Class)
package sample; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; public class HelloApp { public static void main(String[] args) { Resource resource = new ClassPathResource("applicationContext.xml"); BeanFactory factory = new XmlBeanFactory(resource); MessageBean bean = (MessageBean)factory.getBean("messageBean"); bean.sayHello("Spring"); } }applicationContext.xml (Spring Bean Configuration File = Spring Bean Definition File)
'Java > Spring' 카테고리의 다른 글
스프링 XML 설정에서 자바 설정 Import하기 (0) | 2016.01.22 |
---|---|
스프링 @Autowired와 @Qualifier 사용법 (0) | 2016.01.19 |
SpringBoot 서버 포트 변경하기 (0) | 2016.01.07 |
스프링 MVC의 주요 구성 요소 및 처리 흐름 (0) | 2009.12.22 |
스프링의 DI에 대해서... (0) | 2009.12.03 |