你可以貢獻自己的實現org.apache.tapestry5.ioc.Resource
,這可能會阻止需要使用Tapestry的內部API。
@Contribute(ComponentMessagesSource.class)
public static void provideMessages(OrderedConfiguration<Resource> configuration) {
configuration.add("DBMessages", new Resource() {
// implement interface methods
});
}
你可以,當然,構建從一個單獨的服務,提供與數據庫連接或任何你希望從中獲取您的信息資源內的資源實例。棘手的一點可能是如何實現明確爲文件/目錄結構設計的方法,以及更動態的工作。
/**
* Returns a Resource based on a relative path, relative to the folder containing the resource. Understands the "."
* (current folder) and ".." (parent folder) conventions, and treats multiple sequential slashes as a single slash.
* <p/>
* Virtual resources (resources fabricated at runtime) return themselves.
*/
Resource forFile(String relativePath);
或
/**
* Returns the portion of the path up to the last forward slash; this is the directory or folder portion of the
* Resource.
*/
String getFolder();
好吧,我想你得有在掛毯源代碼偷看,看看如何對現有資源實現的工作。