我是 OFBiz 的新手,我正在创建简单的 ofbiz 服务并引用此链接http://www.packtpub.com/article/apache-ofbiz-service-engine-part1
我将实践项目创建为热部署。
我在 servicedef/services.xml 中为 learningFirstService.xml 创建了如下服务
`<service name="learningFirstService" engine="java"
location="org.ofbiz.practice.practice.PracticeServices" invoke="handleParameters">
<description>Our First Service</description>
<attribute name="firstName" type="String" mode="IN" optional="true" />
<attribute name="lastName" type="String" mode="IN" optional="true" />
</service>`
并在 src.org.ofbiz.practice.practice pakcage 中创建了 PracticeServices.java 类并创建了方法
public static Map learningFirstService(DispatchContext dctx, Map context){
System.out.println("learning first service called");
Map resultMap = ServiceUtil.returnSuccess("You have called on service 'learningFirstService' successfully!");
return resultMap;
}
在我的 ofbiz-component.xml 中
<?xml version="1.0" encoding="UTF-8"?>
<ofbiz-component name="practice"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
<resource-loader name="main" type="component"/>
<service-resource type="model" loader="main" location="servicedef/services.xml"/>
<webapp name="practice"
title="Practice"
server="default-server"
base-permission="OFBTOOLS"
location="webapp/practice"
mount-point="/practice"
app-bar-display="true"/>
<classpath type="dir" location="config"/>
</ofbiz-component>
learningforms.xml 如下
<?xml version="1.0" encoding="UTF-8"?>
<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/widget-form.xsd">
<form name="TestingServices" type="single" target="${formTarget}">
<field name="firstName"><text/></field>
<field name="lastName"><text/></field>
<field name="planetId"><text/></field>
<field name="submit"><submit/></field>
</form>
</forms>
并且在controller.xml 中有显示学习表格的请求映射
<request-map uri="TestFirstService">
<event type="service" invoke="learningFirstService" />
<response name="success" type="view" value="TestFirstService" />
</request-map>
<view-map name="TestFirstService" type="screen" page="component://practice/widget/PracticeScreens.xml#learningForm"/>
学习表格成功打开。但是当我点击提交按钮时。它在控制台中给出错误,例如,
Error in request handler:
Exception: org.ofbiz.webapp.event.EventHandlerException
Message: Problems getting the service model (Cannot locate service by name (learningFirstService))
---- cause ---------------------------------------------------------------------
Exception: org.ofbiz.service.GenericServiceException
Message: Cannot locate service by name (learningFirstService)
---- stack trace ---------------------------------------------------------------
org.ofbiz.service.GenericServiceException: Cannot locate service by name (learningFirstService)
org.ofbiz.service.DispatchContext.getModelService(DispatchContext.java:191)
org.ofbiz.webapp.event.ServiceEventHandler.invoke(ServiceEventHandler.java:116)
org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:648)
org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:394)
org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:224)
org.ofbiz.webapp.control.ControlServlet.doPost(ControlServlet.java:87)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:339)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:619)
该错误表明它无法找到我定义的服务。但无法理解它哪里出错了。请帮我。
先谢谢了。
Ankit