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。