2013-10-13 37 views
0

我剛剛開始使用Restlet,而我正在使用版本2.0-M3。我試圖在Web應用程序中使用Spring。當我嘗試訪問我的應用程序中的url/hello時,我收到一個404錯誤。這裏是我的代碼的部分:Restlet和SpringServerServlet收到404錯誤

的web.xml

<servlet> 
    <servlet-name>rest</servlet-name> 
     <servlet-class> 
      org.restlet.ext.spring.SpringServerServlet 
     </servlet-class> 
     <init-param> 
     <param-name>org.restlet.component</param-name> 
      <param-value>helloComponent</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

<servlet-mapping> 
    <servlet-name>rest</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 

ServerResource:

public class MyResource extends ServerResource { 
@Get 
public String getResource() { 
    return "Hello World!"; 
} 
} 

的applicationContext.xml

<bean id="helloComponent" class="org.restlet.ext.spring.SpringComponent"> 
    <property name="defaultTarget" ref="helloAppliction" /> 
</bean> 

<bean id="helloAppliction" class="MyApplication"> 
    <property name="root" ref="router" /> 
</bean> 

<!-- Define the router --> 
<bean name="router" class="org.restlet.ext.spring.SpringBeanRouter"/> 

<!-- Define all the routes --> 
<bean name="/hello" id="helloResource" class="MyServerResource" scope="prototype" autowire="byName" /> 

這裏是日誌中的錯誤信息:

Oct 12, 2013 11:34:59 PM org.restlet.engine.log.LogFilter afterHandle 
INFO: 2013-10-12  23:34:59  127.0.0.1  -  127.0.0.1  8080 GET  /mywebapp/hello -  404  330  -  1  http: 
//localhost:8080  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0 - 

有人可以告訴我,如果你看到任何錯誤?

謝謝! Eric

回答

0

我想你也發佈在Restlet的討論板上了?我會像在那裏一樣回答。

您不會將「/ hello」路徑附加到路由器。您的路由器沒有路由,因此將始終提供404.