HttpInvoker 遠端調用出錯
org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping、org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping,等等。
我用SimpleUrlHandlerMapping和DefaultAnnotationHandlerMapping比較多,其它的基本沒用過。
最近在專案中使用了BeanNameUrlHandlerMapping,發現有這樣一個現象:
如果沒有明確宣告任何處理器對映,spring會預設使用BeanNameUrlHandlerMapping,但如果明確聲明瞭其它的處理器對映,則需要將BeanNameUrlHandlerMapping明確宣告出來,而且在每個包含被對映的bean的配置檔案中都要加入BeanNameUrlHandlerMapping,否則會拋異常:
WARN - No mapping found for HTTP request with URI [/BOSS_SUPPORT/service/httpService] in DispatcherServlet with name 'backend'
2010-01-08 11:14:57 [backend]:253 ERROR - Servlet.service() for servlet backend threw exception
java.io.IOException: Did not receive successful HTTP response: status code = 404, status message = [Not Found]
從異常看,報告沒有找到相應的對映地址,這個現象很是奇怪,也許是我沒有搞清楚,不過在網上也沒有找到相關的說明,希望高手指點。
相關配置檔案如下:
主配置檔案a.xml:
<!-- 定義註解URL對映處理器 -->
<bean id="urlMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors" ref="interceptors" />
<property name="order" value="1"></property>
</bean>
<bean id="beanNameUrlHandlingMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="interceptors" ref="interceptors" />
<property name="order" value="2"></property>
</bean>
包含對映的一個配置檔案b.xml:
<bean id="httpService" name="/httpService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service">
<ref bean="ucService" />
</property>
<property name="serviceInterface" value="com.netqin.baike.service.UcService"/>
</bean>
以上兩個檔案都在伺服器啟動時載入,雖然a.xml中已經聲明瞭BeanNameUrlHandlerMapping,但如果b.xml中沒有宣告BeanNameUrlHandlerMapping,系統就會拋異常。