Tôi đã bắt đầu học Apache CXF với Spring. Trước hết, tôi đã cố tạo một mô hình máy khách/máy chủ đơn giản.Apache CXF + Spring: Tạo một Máy khách Đơn giản
Các server-side là: 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;
}
}
Client-side là: 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>
Vấn đề là: để làm cho công việc của khách hàng tôi đã có thêm dịch vụ. HelloWorld (gói + giao diện) cho dự án của khách hàng. Tôi đã nghe nói rằng trước khi sử dụng một dịch vụ tôi cần phải tạo ra một sơ khai. Vì vậy, nó gây nhầm lẫn cho tôi. Vì vậy, đó là cách tiếp cận chính xác và thực hành tốt nhất (có thể tốt hơn là sử dụng một số cách tiếp cận hợp đồng đầu tiên hoặc tương tự)? Sau đó, tôi muốn thêm WS-Security, vì vậy tôi cần một nền tảng mạnh mẽ =)
Xin cảm ơn trước.
Cảm ơn bạn đã trả lời. Dịch vụ phân phối giao diện như thế nào? – Dmitry
Vì vậy, bạn đề nghị không sử dụng JaxWsProxyFactoryBean? – Dmitry
@WebService chú thích là cần thiết - Tôi đã kiểm tra =) – Dmitry