接上一篇:(三) Spring环境搭建

(一) spring官网下载

官网地址:https://spring.io/ 下载地址:https://repo.spring.io/libs-release-local/org/springframework/spring/5.1.9.RELEASE/spring-framework-5.1.9.RELEASE-dist.zip 下载完成后会发现三个目录,命名很明确。 Docs 目录相关文档。包括一份 API 和一份各种 spring 的使用说明(reference),reference 提供了 HTML.PDF 版本,非常详细。
在这里插入图片描述

(二)spring的核心包

(三) 配置 XML

Spring 的最大的作用就是提供 bean 的管理功能,在 spring 中 bean 的管理是通过 XML 实现的,要 用此功能,需要把 bean 配置到 spring 的 xml。

1. 新建立一个 xml.名字任意,如 applicationContext.xml(推荐),或者 text.xml 都可以

2. 添加 xml 头定义

<?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> </bean> </beans>

① Xmlns(XML NameSpace) 声明命名空间,建议是用网址做命名空间,但并不会去访问改网址, 仅仅是 namespace 和 xsd(xsd 是 spring 这个 xml 的 schema 文件,里面定义配置内容)里 声明的 targetNamespace 保持一致 . 注:这里命名空间是改不了的,其实是在代码中也写死了,可以打开 spring-beans3.2.0.M1-sources.jar 包的 orgspringframeworkeansfactoryxmlBeanDefinitionParserDelegate.java 查看对 http://www.springframework.org/schema/beans这个namespace的定义。 ② schemaLoacation .用于绑定命名空间的 schema 文件,通常是用 URL 值对,中间用空格隔 开,前面 URL 是命名空间,后面 URL 为 schema 的文件地址 ② xsd 的存放地址,如果没有声明,eclipse 去网上下载.

在创建 xml 时,需要导入schema约束,如果联网了会自动缓存文件到本地,提供提示功能,如果没网,在 eclipse 编辑 xml 配置没有提示,需要手动配置xsd schema文件路径。解决如下:可以对 eclipse 中进行 schema 文件的添加 具体是 WindowsàPreferences ,搜索 XML catalog,添加 schema 文件。

1.下载对应的schema到本地, 如:

http://www.springframework.org/schema/beans/spring-beans-4.1.xsd

2.在eclipse中添加

在这里插入图片描述

辰鬼丫
原文地址:https://www.cnblogs.com/Acechengui/p/13635471.html