Apache CXF + Printemps: la Génération d'un Simple Client

J'ai commencé à apprendre le Apache CXF avec le Printemps. Tout d'abord, j'ai essayé de créer un simple modèle client/serveur.

Le côté serveur est:
service.HelloWorld.java

@WebService
public interface HelloWorld {
  String sayHi(String text);
}

service.HelloWorldImpl.java

@WebService(endpointInterface = "service.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
   public String sayHi(String text) {
     return "Hello, " + text;
   }
}

Le côté client est:
client.Client.java
public class Client {

    public static void main(String[] args) {
          ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new  String[] {"cxf-client-servlet.xml"});
          HelloWorld client = (HelloWorld) context.getBean("client");
          System.out.println(client.sayHi("Batman"));
    }
}

cxf-client-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:jaxws="http://cxf.apache.org/jaxws"
 xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://cxf.apache.org/jaxws
    http://cxf.apache.org/schema/jaxws.xsd">

<bean id="client" class="service.HelloWorld" factory-bean="clientFactory" factory-method="create"/>

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

Le problème, c'est de rendre le client le travail, j'ai dû ajouter un service.HelloWorld (forfait + interface) pour les clients du projet. J'ai entendu dire qu'avant d'utiliser un service dont j'ai besoin pour générer un stub. Donc, c'est très confus pour moi. De sorte que, quelle est la bonne approche et quelle est la meilleure pratique (peut-être que c'est mieux d'utiliser un contrat-première approche ou autres choses de ce genre)? Plus tard, je veux ajouter WS-Security, j'ai donc besoin d'un solide background =)

Merci d'avance.

OriginalL'auteur Dmitry | 2012-01-27