轴故障:“服务类必须具有公共访问修饰符”

时间:2011-11-21 17:42:30

标签: java eclipse web-services axis

我正在尝试构建一个简单的Web服务。我按照this tutorial进行操作就可以了。

但是当我改为创建Converter类的接口时,Eclipse自动包括IConverter.classConverter.class,但是当我运行test时,它总是返回这个结果:

<soapenv:Reason>
    <soapenv:Text xml:lang="en-US">
        Service class wtp.IConverter must have public as access Modifier
    </soapenv:Text>
</soapenv:Reason>

我在iConverter及其方法的代码中有public关键字。

这是我的java源代码:

接口:

package wtp;
public interface IConverter {
    public float celToF(float cel);
    public float fToCel(float f);
}

实现:

package wtp;

public class Converter implements IConverter {

    @Override
    public float celToF(float cel) {
        return cel * 9 / 5 + 32;
    }

    @Override
    public float fToCel(float f) {
        return (f - 32) * 5 / 9;
    }
}

的services.xml:

<service name="IConverter">
    <Description>
        Test ws
    </Description>
    <messageReceivers>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
    </messageReceivers>
    <parameter name="ServiceClass" locked="false">wtp.IConverter
    </parameter>
</service>

的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <display-name>TestWS</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
        <welcome-file>/axis2-web/index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <display-name>Apache-Axis Servlet</display-name>
        <servlet-name>AxisServlet</servlet-name>
        <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/servlet/AxisServlet</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>*.jws</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <display-name>Apache-Axis Admin Servlet Web Admin</display-name>
        <servlet-name>AxisAdminServlet</servlet-name>
        <servlet-class>org.apache.axis2.transport.http.AxisAdminServlet</servlet-class>
        <load-on-startup>100</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>AxisAdminServlet</servlet-name>
        <url-pattern>/axis2-admin/*</url-pattern>
    </servlet-mapping>
</web-app>

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

不要将接口名称作为服务类传递 - 传递实现接口的类的名称。 Axis2正在尝试使用反射创建服务类的实例。 services.xml中的参数定义应如下所示:

<parameter name="ServiceClass" locked="false"> wtp.Converter </parameter>