0

WSDL の作成に成功した Java で Web サービスを作成しました。Java で自分の Web サービス用の Web サービス クライアントを作成するのに行き詰まっています。いくつかの jsp クラスから Web サービスを使用したいと考えています。どうすればいいのですか?

@WebService
public interface AddService {
    double getMultipicationResult(double M1, double M2);
}

 @WebService(endpointInterface = "com.sample.AddService")
    public class AddServiceImpl implements AddService {
        public AddServiceImpl() {
        }
        @Override
        public double getMultipicationResult(double M1, double M2) {
            M1 = M1*M2;
            return M1;
        }
    }

私はクライアントを次のように書きました:-

public class AddServiceClient {
    private AddServiceClient() {
    }
    public static void main(String args[]){
    {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"SpringClientWebServices.xml"});
        AddService  client = (AddService)context.getBean("client");
        double response = 0.0;
        response = client.getMultipicationResult(10.0, 20.5);
    }
}

SpringClientWebServices.xml は次のとおりです。

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/jdbc
        http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd      
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">


    <bean id="client" class="com.sample.AddService" 
          factory-bean="clientFactory" factory-method="create"/>

    <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
        <property name="serviceClass" value="com.sample.AddService"/>
        <property name="address" value="http://localhost:8080/sample/services/Addition"/>
    </bean>

</beans>

次のように例外が発生しています:-

Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.cxf.jaxws.JaxWsProxyFactoryBean] for bean with name 'clientFactory' defined in class path resource [SpringClientWebServices.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.cxf.jaxws.JaxWsProxyFactoryBean
4

2 に答える 2

0

JSP から直接サービスを利用したい場合は、次のような JavaScript クライアントを検討してください: http://cxf.apache.org/docs/javascript-client-samples.html

私は、サービス インターフェイスを含む jar を使用し、別の jar で CXF と Spring を使用して動的 Spring クライアントを作成し、それらの依存関係の両方を取り込むことを好みます。これは、CXF サイトにも記載されています。

于 2013-04-25T14:54:07.413 に答える
0

まず、ClassNotFoundException から明らかなように、CXF jar がありません。cxf jar を含めてください。

次に、JSP でのサービスの使用に関しては、最初に main メソッドではなく web.xml を介して Spring コンテナーを初期化する必要があります。Spring MVC を使用し、Web サービスを呼び出して JSP にデータを提供するコントローラーを実装します。

于 2013-04-25T12:51:38.737 に答える