spring(一)环境搭建,sts工具,第一个spring程序

本文介绍了如何搭建Spring环境,包括从指定地址下载所需jar包,如spring-aop、spring-beans等,以及添加commons-logging日志jar。接着讲解了通过sts插件或直接下载STS工具来编写配置文件,以方便开发。最后,展示了如何使用ClassPathXmlApplicationContext创建IOC容器,并从容器中获取并使用Bean。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.搭建Spring环境

1.1下载jar地址

http://maven.springframework.org/release/org/springframework/spring/
spring-framework-4.3.9.RELEASE-dist.zip

1.2开发spring至少需要使用的jar(5个+1个)

spring-aop.jar 开发AOP特性时需要的JAR
spring-beans.jar 处理Bean的jar
spring-context.jar 处理spring上下文的jar
spring-core.jar spring核心jar
spring-expression.jar spring表达式
三方提供的日志jar
commons-logging.jar 日志
下载jcommons-logging.jar地址
https://mvnrepository.com/artifact/commons-logging/commons-logging

2.编写配置文件

为了编写时有一些提示、自动生成一些配置信息:
方式一:增加sts插件
可以给eclipse增加 支持spring的插件:spring tool suite(https://spring.io/tools/sts/all)
下载springsource-tool-suite-3.9.4.RELEASE-e4.7.3a-updatesite.zip,然后在Eclipse中安装:Help-Install new SoftWare… - Add

方式二:
直接下载sts工具(相当于一个集合了Spring tool suite的Eclipse): https://spring.io/tools/sts/

新建:bean configuration … - applicationContext.xml

3.开发Spring程序(IOC)

ApplicationContext conext = new ClassPathXmlApplicationContext(“applicationContext.xml”) ;
//执行从springIOC容器中获取一个 id为student的对象
Student student = (Student)conext.getBean(“student”) ;
可以发现,springioc容器 帮我们new了对象,并且给对象赋了值

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值