2010-09-07 51 views
2

我收到以下錯誤,當我嘗試使用URLResourceLoader訪問接入Velocity模板用於加載模板。無法在URLResourceLoader與速度

org.apache.velocity.exception.ResourceNotFoundException:無法在org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:483)找資源 'http://localhost:8080/myvelocityapp/my-template.vm'

我我能夠看到上述文件,如果我複製粘貼到我的瀏覽器的網址。但是,代碼無法訪問URL。我的模板代碼似乎是正確的,因爲它嘗試使用ClassPathResourceLoader時正常工作。它只是提供問題的url資源加載器。

謝謝。

編輯---

我寫了一個小JUnit來看看是什麼問題:

import java.io.IOException; 
import java.net.MalformedURLException; 
import java.net.URL; 

import junit.framework.TestCase; 

public class TestUrl extends TestCase { 

    protected void setUp() throws Exception { 
     super.setUp(); 
    } 

    public void testVelocity() throws IOException { 
     URL url= new URL("http://localhost:8080/myvelocityapp/my-template.vm"); 
     System.out.println(url.openStream().toString()); 

    } 

    protected void tearDown() throws Exception { 
     super.tearDown(); 
    } 

} 

而且上面的代碼可以訪問的URL。

回答

2

終於找到了問題。

的問題是,「url.resource.loader.root」沒有指定是。