读书人

Spring学习-helloworld运用annotation

发布时间: 2012-10-16 09:57:37 作者: rapoo

Spring学习-helloworld使用annotation配置

1、使用annotation注解需要asm,cglib两个jar包,分别从http://forge.ow2.org/project/showfiles.php?group_id=23&release_id=3334和http://cglib.sourceforge.net/下载并加入build path中

2、新建Spring3HelloWorld类,代码如下:

package spring3annotation;import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class Spring3HelloWorldConfigTest {/** * @param args */public static void main(String[] args) {// Initialize IoC ContainerAnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spring3HelloWorldConfig.class);System.out.println("Calling Bean method: sayHello()");// Retrieve the bean from ContainerSpring3HelloWorld myBean = (Spring3HelloWorld) context.getBean("spring3HelloWorld");myBean.sayHello();}}

?5、运行Spring3HelloWorldConfigTest

?6、英文教程http://www.roseindia.net/spring/spring3/configuration-spring.shtml

?7、asm是轻量级的字节码处理框架,日后再仔细研究?

读书人网 >软件架构设计

热点推荐