spring温习笔记-入门-依赖注入
2013-03-30 23:41
204 查看
Spring容器最大的作用便是解耦合,所有的控制反转、依赖注入其实是一个意思,创建被调用者的实例由Sping容器来完成,然后注入调用者。
spring架包可以去官方下载,也可以移驾这里:点击下载spring3.0.5的架包
创建helloworld实例
1、创建一个工程,引用spring架包、common-logging.jar
2、创建一个bean.xml文件
3、创建一个service文件 其实就类似一个JavaBean
4、运行 Hello,World
5、输出结果
项目打包下载:点击下载
spring架包可以去官方下载,也可以移驾这里:点击下载spring3.0.5的架包
创建helloworld实例
1、创建一个工程,引用spring架包、common-logging.jar
2、创建一个bean.xml文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- 将TestService类部署成Spring容器中的Bean --> <bean id="testService" class="xl.TestService"> <property name="name" value="world"/> </bean> </beans>
3、创建一个service文件 其实就类似一个JavaBean
package xl; public class TestService { private String name; public void setName(String name) { this.name = name; } public void call() { System.out.println("hello,"+name); } }
4、运行 Hello,World
package xl; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpringTest { /** * @param args */ public static void main(String[] args) { ApplicationContext appContext=new ClassPathXmlApplicationContext("bean.xml"); TestService test=appContext.getBean("testService",TestService.class); test.call(); } }
5、输出结果
Hello,World
项目打包下载:点击下载
相关文章推荐
- (学习笔记)spring入门之Bean的依赖注入
- Angular学习笔记(六)之依赖注入入门
- Spring.NET依赖注入框架学习--入门
- 【Spring学习笔记二】-理解依赖注入
- Spring 4 学习笔记6:依赖注入(配置)
- Spring学习笔记--依赖注入
- Spring笔记3-泛型依赖注入
- 框架 day36 Spring3 入门,DI依赖注入,装配bean基于xml/注解, 整合Junit4,配置约束自动提示
- Spring入门--控制反转(IOC)与依赖注入(DI)
- spring学习笔记(1)-spring依赖注入的几种方式
- Spring学习(1):控制反转(IoC)和依赖注入(DI)的详解以及注解(annotation)开发入门案例
- spring学习笔记3——注入依赖对象
- Spring学习笔记----依赖注入的简单实现
- ASP.NET_MVC使用Spring.Net.MVC依赖注入学习笔记
- SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-009-用SPEL给bean运行时注入依赖值
- Spring 学习笔记之依赖注入
- 【JavaWeb-23】spring、IoC控制反转和DI依赖注入入门、基于XML的Bean装配、基于注解的Bean装配
- Spring.net 学习笔记二 依赖注入
- spring学习笔记(一)——控制反转&依赖注入
- Spring学习笔记之泛型依赖注入