Spring 简介
Spring 作者:Rod Johnson
官方网站:http://spring.io/
最新开发包及文档下载地址:https://repo.springsource.org/libs-releaslocal/org/springframework/spring/
核心思想:IOC 控制反转,DI依赖注入,AOP 面向切面;
框架体系
准备工作:
(1)下载spring的jar包
ioc核心 jar 包:
(2)导入工程中,加入构建路径
(3)定义一个java类,HelloWorld类
(4)beans.xml 通过xml注册一个bean到spring 的ioc容器中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="helloWorld" class="org.lanqiao.service.HelloWorld">
</bean>
</beans>
(5)测试类
ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
HelloWorld hw = (HelloWorld) ac.getBean("helloWorld");
hw.hello();