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了对象,并且给对象赋了值