1. 程式人生 > >Spring配置檔案沒有自動提示解決

Spring配置檔案沒有自動提示解決

使用各種xml配置檔案時,都需要新增相應的約束規則,有時候會出現不會自動提示,以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"
    xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation
=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 配置元件掃描器 就是說明你的bean註解在哪個包下 --> <context:component-scan
base-package="com.hk.spring.di01">
</context:component-scan> </beans>

添加了約束,卻還沒有繫結約束檔案,所以沒有提示,特別是在沒有網路的情況下,從約束中可以看出約束檔案的地址在http://www.springframework.org/schema/beans/spring-beans.xsd,還有一個在http://www.springframework.org/schema/context/spring-context.xsd,為了在沒有網路的情況下也可以有提示,就需要繫結本地約束檔案
先複製http://www.springframework.org/schema/context/spring-context.xsd

這個地址
後續步驟如下Window—>Perferences—>MyEclips—>Files and Editors—>XML—>XML Files—>XML Catalog—>User Specified Entries—>Add

然後就會看到這個介面

這裡寫圖片描述
然後,Key Type 選擇URI,Key把你複製的內容貼上進去,Location點選File System(繫結本地xsd)
這裡寫圖片描述


然後找到對應的spring-context.xsd的位置,一般都是在你下載的Spring裡


這裡寫圖片描述
我的是4.2版本,根據自己的版本選擇
這裡寫圖片描述

點選ok,搞定,重新開啟配置檔案,提示就有了
這只是弄好了其中一個,另一個spring-beans.xsd也類似,只是它的本地位置不一樣,其他操作一樣

這裡寫圖片描述