文档介绍:一: S pring 第一天 1 :导入 spring 相关的 jar 包(1) spring-framework- (核心包) 写法: org. springframework …….. (2) spring 第三方依赖包 spring-framework-- 写法: com. springsource. -sources- (第三方包) S pring 开发需要哪些 jar包2: spring 的核心容器默认的写法: (默认文件放置到 src 下,但是也可以更改路径) 可以自定义命名: 在 中引入约束的文件< beans xmlns = "ema/beans" xmlns:xsi = "1/XMLSchema-instance" xsi:schemaLocation = "ema/beans ema/beans/ spring-beans- "> </ beans > 如果你发现在 中不能显示对应的提示:此时 xsd 的文件没有被加载到 myeclips e 中3: spring 加载容器的方式核心对象: 4 :控制反转( IOC ) (1) 概念: 所谓控制反转就是应用本身不负责依赖对象的创建及维护, 依赖对象的创建及维护是由外部容器负责的。这样控制权就由应用转移到了外部容器, 控制权的转移就是所谓反转,目的是为了获得更好的扩展性和良好的可维护性。(2 )代码: 存在一个 Boy 对象: public class Boy { public void display(){ System. out .println( " 我是一个优秀的 Boy !" ); }}在 spring 容器中定义: <? xml version = "" encoding = "UTF-8" ?> < beans xmlns = "ema/beans" xmlns:xsi = "1/XMLSchema-instance" xsi:schemaLocation = "ema/beans ema/beans/spring-beans-" > <!-- 指定在容器中创建一个对象* id :表示在 spring 容器中的惟一标识* class :表示需要构造的类的全路径--> <bean id= "boy" class= "" ></bean> </ beans > 使用 App 进行测试: .; .; .; public class App { public static void main(String[] args) { // Boy boy = new Boy(); // (); /** 使用 spring 容器构造 boy 对象*/ // 使用 applicationContext 加载 spring 容器/** * new ClassPathXmlApplicationContext(): 表示默认加载类路径下的 * new ClassPathXmlApplicationContext(""): 表示类路径下的 * new ClassPathXmlApplicationContext("cn/itcast/a_ioc/"): 包下的 */ ApplicationContext ac= new ClassPathXmlApplicationContext("cn/itcast/a_ioc/"); // 获取容器下的 id 指定的对象 Boy boy = (Boy) ("boy"); (); }}5 :依赖注入( DI) 概念: 所谓依赖注入就是指: 在运行期, 由外部容器动态地将依赖对象注入到另一个对象的组件中。类中定义:创建 2 个对象,一个 Boy 对象和一个 Girl ; public class Boy { public void di