spring框架的主要優勢之一就是其分層架構,分層架構允許使用者選擇使用哪一個組件,同時爲 J2EE 應用程序開發提供集成的框架。下面yjbys小編爲大家準備了關於集成spring與Web容器教程,歡迎閱讀。
1.創建HelloWorld 接口類
package oworld;
import ethod;
import aram;
import esult;
import ervice;
@WebService
public interface HelloWorld {
@WebMethod
@WebResult String sayHi(@WebParam String text);
}
2.創建HelloWorld實現類
package oworld;
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String name) {
String msg = "Hello " + name + "!";
return msg;
}
}
3.修改文件
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"_2_" >
cxfstudy
cxf
ervlet
1
cxf
/ws/*
extLoaderListener
contextConfigLocation
classpath*:**/
4.創建spring配置文件並放在classpath路徑下
xmlns:xsi="" xmlns:jaxws=""
xsi:schemaLocation="
">
5.創建測試類
package oworld;
import icationContext;
import sPathXmlApplicationContext;
public class SpringClient {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("");
HelloWorld helloworld = (HelloWorld)ean("helloworldClient");
tln(i("kongxx"));
}
}
6.測試
6.1 首先啓動tomcat或者使用maven的jetty,並訪問http://localhost:9000/ws/HelloWorld?wsdl來驗證web service已經啓動並且生效;
6.2 然後運行測試類來驗證web service。