Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 使用HttpInvokerServiceExporter给出500个错误代码_Spring_Spring Remoting - Fatal编程技术网

Spring 使用HttpInvokerServiceExporter给出500个错误代码

Spring 使用HttpInvokerServiceExporter给出500个错误代码,spring,spring-remoting,Spring,Spring Remoting,在过去的两天里,我一直在努力使用HttpInvokerServiceExporter公开一个服务。错误说明未收到成功的HTTP响应下面是完整的堆栈跟踪以了解详细信息。代码在Git repo中签入。链接是- 我已经正确地遵循了文档,并执行了所有步骤。以下是服务接口: package com.remoting; public interface AccountService { public int add(int a, int b); } 然后是服务实现 package com.rem

在过去的两天里,我一直在努力使用HttpInvokerServiceExporter公开一个服务。错误说明
未收到成功的HTTP响应
下面是完整的堆栈跟踪以了解详细信息。代码在Git repo中签入。链接是-

我已经正确地遵循了文档,并执行了所有步骤。以下是服务接口:

package com.remoting;

public interface AccountService {
    public int add(int a, int b);
}
然后是服务实现

package com.remoting;
public class AccountServiceImpl implements AccountService {
    @Override
    public int add(int a, int b) {
        return a + b;
    }
}
然后是web.xml

<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
    <display-name>spring-remoting</display-name>

<!-- The front controller of this Spring Web application, responsible for 
    handling all application requests -->
    <servlet>
        <servlet-name>accountExporter</servlet-name>
        <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>accountExporter</servlet-name>
        <url-pattern>/AccountService</url-pattern>
    </servlet-mapping>
</web-app>
现在要调用该服务,我有两个jsp文件和一个helper类来加载bean并调用函数:

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
  </head>
  <body>
    <form action="process.jsp">
    Enter Number:<input type="text" name="number" /> <input type="submit"
        value="cube" />
    </form>
  </body>
</html>
applicationContext.xml位于
/WEB-INF/classes
目录中


请告诉我哪里出了问题

我知道这是一个老问题,但今天我在
HttpInvokerClientInterceptor
中偶然发现了相同的错误。在我的例子中,原因是服务器和客户端使用了两种不同的Java对象版本。由于使用Java对象(de)序列化,请确保服务器和客户端使用相同版本的对象/类


提到,它也可能意味着只使用相同的
serialVersionUID
和不同的类。

我知道这是一个老问题,但今天我偶然发现了发生在
HttpInvokerClientReceptor
中的相同错误。在我的例子中,原因是服务器和客户端使用了两种不同的Java对象版本。由于使用Java对象(de)序列化,请确保服务器和客户端使用相同版本的对象/类


提到,它也可能意味着只使用相同的
serialVersionUID
和不同的类。

我真的希望您不会在实际应用程序中使用该代码。您不应该将Java代码放在JSP的旁边,而不应该仅仅因为您需要一个bean而重新创建应用程序上下文(基本上,每次这样做时,您都在重新创建整个应用程序,因此除非您想遇到内存问题、事务问题、奇怪的调试问题,否则就应该这样做)。您正在调用的URL以及
DispatcherServlet
的映射都是错误的。我真的希望您不要在实际应用程序中使用该代码。您不应该将Java代码放在JSP的旁边,而不应该仅仅因为您需要一个bean而重新创建应用程序上下文(基本上,每次这样做时,您都在重新创建整个应用程序,因此除非您想遇到内存问题、事务问题、奇怪的调试问题,否则就应该这样做)。您正在调用的URL以及
DispatcherServlet
的映射都是错误的。
 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

<bean id="accountService" class="com.remoting.AccountServiceImpl"></bean>

<bean name="accountExporter"
    class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
    <property name="service" ref="accountService" />
    <property name="serviceInterface" value="com.remoting.AccountService" />
</bean>
<bean id="httpServer"
    class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
    <property name="serviceUrl" value="http://localhost:8080/spring-remoting/AccountService"></property>
    <property name="serviceInterface" value="com.remoting.AccountService"></property>
    </bean>

</beans>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
  </head>
  <body>
    <form action="process.jsp">
    Enter Number:<input type="text" name="number" /> <input type="submit"
        value="cube" />
    </form>
  </body>
</html>
<jsp:include page="index.jsp"></jsp:include>  
<hr/>  
<%@page import="com.remoting.ClientInvoker"%>  

<%  
  int number=Integer.parseInt(request.getParameter("number"));  
  out.print("sum of "+number+" is: "+ClientInvoker.sum(number));  
%>  
package com.remoting;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;  

public class ClientInvoker {  
    public static int sum(int number){  
        ApplicationContext context = new      ClassPathXmlApplicationContext("classpath:applicationContext.xml");  
        AccountService service = (AccountService)context.getBean("httpServer");  
        return service.add(4, 4);  
    }  
}