IoC 용기 기본 인 스 턴 스

2626 단어 spring
참고 주소:http://sishuok.com/forum/blogPost/list/2428.html
maven 프로젝트 를 만 들 고 pom.xm 에 의존 팩 을 추가 합 니 다.
        


    org.springframework
    spring-context
    4.0.0.Release



    org.springframework
    spring-core
    4.0.0.Release



    org.springframework
    spring-beans
    4.0.0.Release



    org.springframework
    spring-jdbc
    4.0.0.Release




    org.springframework
    spring-context-support
    4.0.0.Release




    org.springframework
    spring-jms
    4.0.0.RELEASE

HelloApi
package com.eastcom.first.spark.data.spring;

public interface HelloApi {

	public void sayHello();

}

HelloImpl
package com.eastcom.first.spark.data.spring;

public class HelloImpl implements HelloApi {

	@Override
	public void sayHello() {
		// TODO Auto-generated method stub

		System.out.println("this is a spring hello world!");

	}

}

HelloTest
package com.eastcom.first.spark.data.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class HelloTest {

	public static void main(String[] args) {

		testHelloWorld();

	}

	public static void testHelloWorld() {

		String confDir = "file:D:/newworkspace/my-study-spark/config/helloworld.xml";
		// 1、           IoC  
		ApplicationContext context = new ClassPathXmlApplicationContext(confDir);
		// 2、      Bean,      “      ,       ”
		HelloApi helloApi = context.getBean("hello", HelloApi.class);
		// 3、      
		helloApi.sayHello();
	}
}

좋은 웹페이지 즐겨찾기