Spring入门

1.搭建Spring环境

下载jar
https://maven.springframework.org/release/org/springframework/spring/

spring-framework-4.3.9.RELEASE-dist.zip
开发spring至少需要使用的jar(5个+1个):
spring-aop.jar          //开发AOP特性时需要的JAR
spring-beans.jar	//处理Bean的jar		 <bean>
spring-context.jar	//处理spring上下文的jar	 <context>
spring-core.jar		//spring核心jar
spring-expression.jar	//spring表达式
第三方提供的日志jar
commons-logging.jar	//日志

2.编写配置文件工具(如果使用eclipse)

方法一:
为了编写时有一些提示、自动生成一些配置信息,可以给eclipse增加支持spring的插件:
(STS)spring tool suite(https://spring.io/tools/sts/all)
方法二:
直接下载sts工具(相当于集成了spring的eclipse)

新建: bean configuration…—applicationContext.xml //Spring 配置文件
[New–>XML Configuration file–>Spring Config]

3.SpringIOC容器:

创建对象、给对象的属性赋值
前提是:该bean类必须存在无参构造。

开发Spring程序:

 ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    //直接从springIOC容器中获取一个id为student的对象
    Student student = (Student)context.getBean("student");

 可以发现,SpringIOC容器:帮我们new了对象,并且给对象赋了值。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值