2014-04-09 22 views
0

我有問題,爲我的索引設置正確的路徑。如果它位於我的Spring應用程序中,它會很好,因爲即使在我將應用程序部署到Cloudbees後,它也可以工作。用Hibernate Search和Spring指定索引路徑

這是我obejct,我試圖指數:

@Entity 
@Table(name="educations") 
@Indexed(index="educations") 
public class Education { 

我已經中的servlet-context.xml中以下內容:

<resources mapping="/resources/**" location="/resources/"/> 

我指定這樣的Lucene索引路徑:

Properties props = new Properties(); 
props.put("hibernate.search.default.indexBase", "resources/lucene/indexes"); 
entityManagerFactory.setJpaProperties(props); 

這不會給我任何錯誤,但我無法找到該文件夾​​,我不明白。我試圖尋找它。

我也試過:

props.put("hibernate.search.default.indexBase", "classpath:/lucene/indexes"); 

props.put("hibernate.search.default.indexBase", "/resources/lucene/indexes"); 

但仍然無法找到該文件夾​​。然而,經過一段時間的努力,我試圖把它放在我的主目錄。 (這可能會部署到雲環境時以後給我的問題):

props.put("hibernate.search.default.indexBase", "/lucene/indexes"); 

我得到以下

Cannot write into index directory: /lucene/indexes for index educations 

所以我認爲它是一個權限錯誤。我嘗試在終端(OSX)以下:

sudo chmod -R u+rwX /lucene/indexes/ 

sudo chmod -R 755 /lucene/indexes/ 

但還是同樣的錯誤。有人可以在此傳播一些信息嗎?

謝謝!

編輯: 經過一些更多的調查後,我相信這是一個權限問題。如果我指定Spring應用程序根目錄的完整路徑,它將起作用。如果沒有給出完整的路徑,我仍然不知道如何指定。

回答

1

相對路徑與Java進程從其啓動的目錄相關。如果在腳本的目錄中有一些啓動腳本或類似的外觀。絕對路徑工作正常,但當然你需要寫入權限。

如果您想爲您的案例提供更通用的解決方案,可以在啓動應用程序時將正確的目錄設置爲系統屬性,並在創建屬性時從此處讀取該目錄。或者您嘗試以另一種方式在運行時確定應用程序的完整路徑。