1:Webservice
@WebService
public interface MessageWebservice {public String getName();
}
2:WebserviceImpl
@WebService(endpointInterface = "study.webService.message.messageWS.MessageWebservice")
public class MessageWebserviceImpl implements MessageWebservice {
public String getName(String type,String PageNum,String PageSize) {
// 查询结果
String resultStr = "";
// 数据查询用service(接口 实现类的运用)
MvcService mvcServiceImpl = (MvcService) BeanService.getBean("mvcServiceImpl");
}
3:BeanService
package study.system.service;
import javax.servlet.ServletContext;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;
@Component
public class BeanService implements ApplicationContextAware, ServletContextAware
{
/**
* Spring容器上下文
*/
public static ApplicationContext context;
private static ServletContext servletContext;
/**
* 取得Bean对象
* @param beanName bean名
* @return ObjectBean对象
*/
public static Object getBean(String beanName)
{
if (context != null)
return context.getBean(beanName);
return null;
}
/**
* 判断对象是否存在
* @param beanName
* @return
*/
public static Boolean containsBean(String beanName)
{
if (context != null)
{
return context.containsBean(beanName);
}
return false;
}
/**
* 取得Bean对象
* @param beanName bean名称
* @param clazz bean类型
* @return ObjectBean对象
*/
public static <T> T getBean(String beanName, Class<T> clazz)
{
if (context != null)
{
return context.getBean(beanName, clazz);
}
return null;
}
/**
* 根据类型取得Bean对象
* @param clazz bean类型
* @return ObjectBean对象
*/
public static <T> T getBean(Class<T> clazz)
{
if (context != null)
{
return context.getBean(clazz);
}
return null;
}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
{
context = applicationContext;
}
public static ApplicationContext getContext()
{
return context;
}
public static ServletContext getServletContext()
{
return servletContext;
}
public void setServletContext(ServletContext _servletContext)
{
servletContext = _servletContext;
}
}
4:其中MvcService 就是一般mvc取数据的service
public interface MvcService {
}
5:其中MvcServiceImpl 就是一般mvc取数据的Impl@Service
public class MvcServiceImpl implements MvcService {
}
6:配置文件application-webservice.xml
<bean id="message" class="study.webService.message.messageWS.impl.MessageWebserviceImpl"/>
<jaxws:endpoint id="getName" implementor="#message" address="/getName"/>