今天试着写了个httpInvoker做远程调用,以便项目以后要扩展成分布式开发的。
但是一直报404找不到错误,我试着查了一下,确定自己配置文件都没有写错。把代码贴出来 希望各位高手解答疑惑 谢谢server端web.xml
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:applicationContext*.xml,
    /WEB-INF/remoting-servlet.xml</param-value>
  </context-param>
  
  
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <!-- Test httpInvoker configuration -->
   <servlet>
  <servlet-name>remoting</servlet-name>
  <servlet-class>
   org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet> <servlet-mapping>
  <servlet-name>remoting</servlet-name>
  <url-pattern>/remoting/*</url-pattern>
 </servlet-mapping>  <!-- Test httpInvoker configuration end **********-->remoting-servlet.xml:<bean id="productService" class="com.fifanrg.services.ProductServiceImpl">
<property name="productDao" ref="productDao"></property>
</bean><!--httpinvoker config   --> 
<bean name="/ProductService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
  <property name="service" ref="productService"/>
  <property name="serviceInterface" value="com.fifanrg.services.ProductService"/>
</bean>
客户端BeanHttpInvoker.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
  "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean class="com.fifanrg.actions.ProductAction">
 <property name="productService" ref="httpInvokerProxy"/>
</bean>
<bean id="httpInvokerProxy" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
  <property name="serviceUrl" value="http://localhost:7001/AssiTwo/remoting/ProductService"/>
  <property name="serviceInterface" value="com.fifanrg.services.ProductService"/>
</bean>
</beans>
测试代码:public class TestHttpInvoker { public static void main(String[] args) {
  ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
    "BeanHttpInvoker.xml");
  ProductAction productAction = (ProductAction) applicationContext
    .getBean("com.fifanrg.actions.ProductAction");
  Catalog catalog = productAction.getProductService().findCatalogById(11078);
 System.out.println(catalog.getC_title());
}
[color=#FF0000]错误信息:
Exception in thread "main" org.springframework.remoting.RemoteAccessException: Could not access HTTP invoker remote service at [http://localhost:7001/AssiTwo/remoting/ProductService]; nested exception is java.io.IOException: Did not receive successful HTTP response: status code = 404, status message = [Not Found]
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.convertHttpInvokerAccessException(HttpInvokerClientInterceptor.java:211)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:160)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy0.findCatalogById(Unknown Source)
at com.fifanrg.test.TestHttpInvoker.main(TestHttpInvoker.java:16)
Caused by: java.io.IOException: Did not receive successful HTTP response: status code = 404, status message = [Not Found]
at org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor.validateResponse(SimpleHttpInvokerRequestExecutor.java:139)
at org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor.doExecuteRequest(SimpleHttpInvokerRequestExecutor.java:62)
at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.executeRequest(AbstractHttpInvokerRequestExecutor.java:134)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:191)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:157)
... 4 more
[/color]
就是会报404错误,但我实在看不出来哪里配置有错。
我直接在url里面输入http://localhost:7001/AssiTwo/remoting/ProductService
也找不到 
希望各位高手支支招啊!!
分全给了!急啊!

解决方案 »

  1.   

    Exception in thread "main" org.springframework.remoting.RemoteAccessException: Could not access HTTP invoker remote service at [http://localhost:8099/remoteServer]; nested exception is java.io.IOException: Did not receive successful HTTP response: status code = 404, status message = [/remoteServer/]
    at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.convertHttpInvokerAccessException(HttpInvokerClientInterceptor.java:211)
    at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:144)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy0.getString(Unknown Source)
    at test.TestRemote.main(TestRemote.java:16)
    Caused by: java.io.IOException: Did not receive successful HTTP response: status code = 404, status message = [/remoteServer/]
    at org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor.validateResponse(SimpleHttpInvokerRequestExecutor.java:146)
    at org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor.doExecuteRequest(SimpleHttpInvokerRequestExecutor.java:65)
    at org.springframework.remoting.httpinvoker.AbstractHttpInvokerRequestExecutor.executeRequest(AbstractHttpInvokerRequestExecutor.java:136)
    at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:191)
    at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:173)
    at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:141)
    ... 4 more
      

  2.   

    remoting-servlet.xml加上:
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/ProductService">/ProductService</prop>
     
    </props>
    </property>
    </bean>