问题描述
|
我正在尝试使用jsonrpc4j json-rpc库。不幸的是,它无法按预期工作...
实际上,我的服务根本没有映射。这是我的一些servlet-context.xml,我正在使用AnnotationMethodHandlerAdapter(也许这是问题吗?):
<bean id=\"assistenzaJsonService\"
class=\"it.jsoftware.jacciseweb.assistenza.jsonrpcservices.AssistenzaJSonServiceImpl\"></bean>
<bean name=\"/AssistenzaServices.json\" class=\"com.googlecode.jsonrpc4j.spring.JsonServiceExporter\">
<property name=\"service\" ref=\"assistenzaJsonService\" />
<property name=\"serviceInterface\"
value=\"it.jsoftware.jacciseweb.assistenza.jsonrpcservices.AssistenzaJSonService\" />
</bean>
该应用程序映射在hostname.com/Appname上,如果我尝试使用hostname.com/Appname/AssistenzaServices.json,则得到404。
线索?
解决方法
您不能直接打
AssistenzaServices.json
。如果这样做,您肯定会得到404。
您缺少JSONrpc-spring流程。
而不是在浏览器中按AssistenzaServices.json
,而是在配置时按AssistenzaServices.html
或类似的东西。单击它后,映射到AssistenzaServices.html
的java类和dojo.js
文件将起作用。 Dojo.js
文件serviceHandler将使用AssistenzaServices.json
映射一个类以获取要在AssistenzaServices.html
上显示的结果。
,jsonrpc4j \主页上的示例假定您使用\“ BeanNameUrlHandlerMapping \”。
我使用了\“ SimpleUrlHandlerMapping \”,它给了我404。
我通过将其添加到servlet.xml中解决了它
<bean class=\"org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping\"/>
它使用以下代码(接口配置为gotch4)工作:
<script type=\"text/javascript\">
dojo.require(\"dojox.rpc.Service\");
dojo.require(\"dojox.rpc.JsonRPC\");
service = new dojox.rpc.Service({
envelope : \"JSON-RPC-1.0\",transport : \"POST\",target : \"http://localhost:8080/ajax/json/UserService.json\",services : {
helloSir : {
parameters : [ {
type : \"string\"
} ]
}
}
});
var response = service.helloSir(\"victorius\");
console.log(response);
</script>