Spring学习-helloworld使用annotation配置
2010-08-28 16:32
68 查看
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; public class Spring3HelloWorld { public void sayHello(){ System.out.println("Hello world~!!"); } }
3、新建Spring3HelloWorldConfig,代码如下:
package spring3annotation; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class Spring3HelloWorldConfig { public @Bean Spring3HelloWorld spring3HelloWorld(){ return new Spring3HelloWorld(); } }
4、新建Spring3HelloWorldConfigTest,代码如下:
package spring3annotation; import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class Spring3HelloWorldConfigTest { /** * @param args */ public static void main(String[] args) { // Initialize IoC Container AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( Spring3HelloWorldConfig.class); System.out.println("Calling Bean method: sayHello()"); // Retrieve the bean from Container Spring3HelloWorld myBean = (Spring3HelloWorld) context .getBean("spring3HelloWorld"); myBean.sayHello(); } }
5、运行Spring3HelloWorldConfigTest
6、英文教程http://www.roseindia.net/spring/spring3/configuration-spring.shtml
7、asm是轻量级的字节码处理框架,日后再仔细研究?
相关文章推荐
- Spring学习笔记 使用annotation配置实现Bean的auto-wiring (自动绑定)
- Spring3.0.2 使用全Annotation 与 Hessian 兼容配置
- 使用Annotation编写Entity减少Spring,hibernate配置。
- SSH与SSM学习之Spring09——Spring使用注解配置
- [转]spring学习笔记:annotation的使用2
- spring学习小结7_使用工厂方法来配置bean:静态工厂方法和实例工厂方法
- Spring学习之使用XML配置AOP
- 扩展Spring——使用 Annotation将配置资源注入到Bean中
- Spring学习笔记(18)----使用Spring配置文件实现事务管理
- [跟我学Spring学习笔记][DI配置与使用]
- spring boot 学习(四)Druid连接池的使用配置
- 【SSH】Spring学习(二)使用注解配置Spring、安装STS插件、Spring与junit整合测试、AOP
- Spring学习笔记之RedisTemplate的配置与使用教程
- Spring Boot 学习13--使用Druid和监控配置
- Spring2.5注解(标注)学习笔记(使用annotation代替XML)
- 关于使用注解的Spring配置文件的配置<context:annotation-config/>&&<context:component-scan base-package=”XX.XX”/>
- Spring学习笔记 在XML配置文件中使用properties文件的键值
- Spring学习笔记--使用Spring基于Java的配置
- 【spring in action 学习--springMVC搭建】在不使用web.xml的情况下,配置Srping MVC工程
- SpringBoot学习笔记(7) SpringBoot整合Dubbo(使用yml配置)