1. 程式人生 > >java 約束配置檔案和本地約束

java 約束配置檔案和本地約束

一、尋找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的配置檔案 沒聯網也有提示了