2015-03-31 54 views
0

我讀Spring documentation和整個下面的文字來:什麼是配置的彈簧驗證?

Spring容器驗證每個bean的配置,創建 容器。

對我來說,它不是很清楚他們的意思是什麼意思Spring容器驗證配置?在我們的項目,我們有xml -configuration文件:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
      http://www.springframework.org/schema/tx 
      http://www.springframework.org/schema/tx/spring-tx.xsd"> 

    <!-- beans --> 

</beans 

難道僅僅是一個xml -validation相對於標籤bean或什麼內定義的架構位置?你能解釋嗎?

如果我們提供基於Java或基於註釋的配置,那麼驗證將會是什麼?

回答

1

無論您配置ApplicationContext的方式如何,驗證或多或少都是相同的。驗證只包含對bean關係的初始檢查。例如,如果聲明瞭一個bean firstBean,它在其某個屬性中引用了一個bean secondBean,但secondBean未在上下文中聲明,那麼在它嘗試初始化bean本身之前,容器會失敗。

+0

因此,在驗證bean之前執行xml驗證 – user3663882 2015-03-31 16:12:00

+0

是的,這是解析的一部分。 – 2015-03-31 16:26:03