一、尋找spring配置文件約束頭(也可直接復制已有的)
1.在本地文件夾解壓spring核心包(dist)
例:核心包的約束位置(D:\JavaSources\spring-framework-4.2.4.RELEASE\docs\spring-framework-reference\html\xsd-configuration.html)
打開此網頁,在網頁最下面為spring約束頭
<?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="foo" class="x.y.Foo"> <meta key="cacheName" value="foo"/> <property name="name" value="Rick"/> </bean> </beans>
二、配置本地約束 可以在xml中有提示 否則約束頭只有在聯網時寫配置文件才有有智能提示
一、dtd形式本地約束
例:struts本地約束
1.找到 xml約束文件配置位置: windows --» preferences --» XML Catalog
2.設置自己需要配置的 URI ,添加本地的 DTD 約束文件
3.重新打開配置文件即可
二、xsd形式本地約束
例:spring本地約束
spring配置本地約束 可以在xml中有提示 否則約束頭只有在聯網有提示
1.在本地文件夾解壓spring約束包(schema)或核心包(dist)
例:核心包的約束位置(D:\JavaSources\spring-framework-4.2.4.RELEASE\schema\beans),用下面的最新的約束文件
2.先復制spring配置文件約束頭的配置信息以備使用(http://www.springframework.org/schema/beans/spring-beans.xsd)
3.在eclipse中 window--》preferences--》搜索 xml catalog
4.點擊ADD --》 file system --》選擇本地的約束文件位置
5、在 key type 中選擇 Schema location
6.將復制的約束信息粘到key中
7. ok保存重新打開配置文件即可
之后再編寫spring的配置文件 沒聯網也有提示了