webService学习之cxf与spring的简单整合
- - 企业架构 - ITeye博客一:先把cxf的jar包导进去,我是直接在官网下载的cxf的包,解压后直接把lib文件夹里的jar一次. 性全部丢进去了,因为在学习,还不知道哪些包要哪些包不要的,所以干脆直接放进去. . . .
import javax.jws.WebService;
@WebService
public interface HelloWorld {
void sayHi(String name);
}
package test.wervice.impl;
import javax.jws.WebService;
import test.wervice.HelloWorld;
@WebService(endpointInterface="test.wervice.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
public void sayHi(String name) {
System.out.println("helloWorld"+name);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 配置application的加载 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置cxf的servlet -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/cxf/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 实现接口的bean -->
<bean id="hello" class="test.wervice.impl.HelloWorldImpl"/>
<!--第一种配置-->
<jaxws:endpoint address="/HelloWorld" >
<jaxws:implementor ref="hello" />
</jaxws:endpoint>
<!-- 第二种配置方法 -->
<!-- <jaxws:endpoint address="/HelloWorld" implementor="test.wervice.impl.HelloWorldImpl"/> -->
</beans>