加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

WebService认识三(Spring整合)

发布时间:2020-12-16 23:42:58 所属栏目:安全 来源:网络整理
导读:前言:因为通常情况下,我们都是用Spring来整合其它框架,所以这里我们不在一、二的基础上进行操作,而是新建一个工程,然后拷贝src下的java代码和db.properties文件到新的工程中,再添加jar。 1:导入spring的jar,这里闲麻烦,把3.1的dist里面的jar都导进

前言:因为通常情况下,我们都是用Spring来整合其它框架,所以这里我们不在一、二的基础上进行操作,而是新建一个工程,然后拷贝src下的java代码和db.properties文件到新的工程中,再添加jar。

1:导入spring的jar,这里闲麻烦,把3.1的dist里面的jar都导进来了,在导入cxf的jar如下:

spring的jar这里就不展示了

2:建立beans.xml文件,保存在src下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.0.xsd
	http://cxf.apache.org/jaxws
	http://cxf.apache.org/schemas/jaxws.xsd">
 	<import resource="classpath:META-INF/cxf/cxf.xml"/>
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

	<bean id="userSerivce" class="org.wjlmgqs.service.imp.UserServiceImp"/>
	<jaxws:server id="userWebService" serviceClass="org.wjlmgqs.service.UserService" address="/user">
	    <jaxws:serviceBean>
	        <ref bean="userSerivce"/>
	    </jaxws:serviceBean>
		<!--
		<jaxws:inInterceptors>
        	<ref bean="inMessageInterceptor"/>
	    </jaxws:inInterceptors>
	    <jaxws:outInterceptors>
	        <ref bean="outLoggingInterceptor"/>
	    </jaxws:outInterceptors>
		-->
	</jaxws:server>	
<!-- 上面通过jaxws:server来发布服务,还可以通过下面的方式实现	
	<bean id="userSerivce" class="org.wjlmgqs.service.imp.UserServiceImp"/>
	<jaxws:endpoint id="userWebService" implementor="#userSerivce" address="/user"/>
-->		
</beans>

3:修改web.xml,如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:beans.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<servlet>
		<servlet-name>CXFServlet</servlet-name>
		<display-name>CXF Servlet</display-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>/webservice/*</url-pattern>
	</servlet-mapping>
</web-app>

4:浏览器访问:http://localhost:8080/SpringWebService/webservice/user?wsdl

结果同WebService认识二一样

该工程源码下载:下载源码

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读