Spring配置檔案中的import

2021-07-31 02:14:04 字數 483 閱讀 4571

在實際的專案開發中,我們往往會分為很多不同的包,如果遇見為不同的包都設定spring配置檔案的情況,都寫在乙個總的配置檔案中,難免會造成配置檔案內容臃腫,不易閱讀的情況。

在spring中,可以把配置檔案分散到各個模組中,然後在總的配置檔案中通過import元素引入這些配置檔案:

1.預設情況下,使用相對路徑來輔助查詢配置檔案

2.spring還提供了兩種字首標記來輔助查詢配置檔案:

(1)[classpath:]:表示從classpath開始尋找後面的資源檔案

(2)[file:]:表示使用檔案系統的方式尋找後面的檔案(檔案的完整路徑)

例如:

注:classpath:***xx:相當於/win-inf/classes/***xx

如果使用了classpath那就表示只會到你的class路徑中去查詢檔案

另外還有乙個classpath*:,它表示不僅會在class路徑中去查詢檔案,還會在jar中去查詢檔案

Spring中的配置檔案檔案位置

org.springframework.web.context.contextloaderlistenerspring就會被自動載入 contextconfiglocation這裡寫路勁 注 以上路徑只是舉例,具體使用還是要針對真是專案的 1 spring配置檔案在web inf下面 這種情況你可以...

spring配置檔案

1 配置檔案的簡化 1 屬性的 property name foo value foovalue value property 簡化為 property name foo value foovalue 2 引用bean property name foo ref bean foobean prope...

spring配置檔案

context annotation config 是用於啟用那些已經在spring容器裡註冊過的bean上面的註解,也就是顯示的向spring註冊 autowiredannotationbeanpostprocessor commonannotationbeanpostprocessor pers...