webservice的发布(服务端)
1.web,xml配置发布监听器
2.监听类的编写
3.接口的编写
*** 该webservice发布会后 http://localhost:8089/user 链接即可访问
http://localhost:8089/user?wsdl 也可访问 并返回xml格式
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>Archetype Created Web Application</display-name>
<!-- 扫描加载配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/applicationContext-mvc.xml,
classpath:spring/applicationContext.xml,
classpath:spring/applicationContext-dataSource.xml
</param-value>
</context-param>
<!--log4j配置文件开始-->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- webservice发布的监听器 -->
<listener>
<listener-class>com.fxb.listener.MyListener</listener-class>
</listener>
<!-- 统计在线人数 监听器 -->
<listener>
<listener-class>com.fxb.listener.MyListener2</listener-class>
</listener>
<!-- post方式提交 统一字符编码过滤器 -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- springmvc拦截所有的请求交由各个处理器 -->
<servlet>
<servlet-name>springMvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
监听类MyListener.java
package com.fxb.listener;
import javax.servlet.ServletContextEvent;
import javax.xml.ws.Endpoint;
import org.springframework.web.context.ContextLoaderListener;
import com.fxb.service.impl.UserServiceImpl;
public class MyListener extends ContextLoaderListener {
public void contextInitialized(ServletContextEvent event) {
String address="http://localhost:8008/user"; //该地址可以是任意,端口号自己确定 发布后该链接可以访问
Endpoint.publish(address,new UserServiceImpl()); //是将服务发布到本地的jdk自带的web容器中
super.contextInitialized(event); //contextInitialized也就是监听器类的main入口函数
}
}
UserServiceImpl.java
package com.fxb.service;
import org.springframework.stereotype.Service;
public interface UserService {
void save () throws Exception;
}