我試圖通過使用方法getResourcePaths() in ExternalContext獲取WAR文件中的資源路徑。但如果該方法被@Schedule
調用,該怎麼辦?在這種情況下,FacesContext爲空。如何在沒有FacesContext的情況下獲取資源路徑?
@Schedule(hour = "*", minute = "0,30", second = "0")
public void foo() {
ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
Set<String> resources = ctx.getResourcePaths("/WEB-INF/");
...
}
我知道FacesContext只在請求中有效。還有其他一些竅門嗎?
我希望你不要在你的EJB類中使用'FacesContext'。 –
我在我的資源中有一些xml文檔,我想在EJB服務類中使用它。我不想在我的應用程序中對文件名進行硬編碼。所以我想知道如何以編程方式查詢這些名稱(不使用'FacesContext')。 – Tomestos