androidpn server 通过Spring与restful webservice整合
来源:互联网 发布:淘宝怎么发安能快递 编辑:程序博客网 时间:2024/06/02 02:02
前面说过androidpn server的启动日志分析,有个小错误:
就是在 XmppServer 的start()方法里面有一个加载spring-config.xml的步骤。
在这里加载的spring context 与在web.xml中通过springContextListeners加载的上下文环境是相互独立的。
之前的文章也说过,restful webservice通过spring进行加载。
本文说明如何修改androidpn,让androidpn 与 restful webservice 相互可见。
一、禁止XmppServer加载spring-config.xml文件
1、注释掉 spring-config.xml加载
locateServer(); serverName = Config.getString("xmpp.domain", "127.0.0.1").toLowerCase();// context = new ClassPathXmlApplicationContext("spring-config.xml"); log.info("Spring Configuration loaded.");
2、注释掉getBean()
// public Object getBean(String beanName) {// return context.getBean(beanName);// }
3、注释掉成员变量
// private ApplicationContext context;
二、修改 ServiceLocator
1、 ServiceLocator 实现 ApplicationContextAware 接口
2、增加 ApplicationContext context变量
3、增加 ServiceLocator serverLocator 变量
public class ServiceLocator implements ApplicationContextAware {private static ApplicationContext context = null;private static ServiceLocator servlocator = null;
4、增加 ApplicationContext 的Setter/Getter
@Overridepublic void setApplicationContext(ApplicationContext arg0) throws BeansException {context = arg0;}public ApplicationContext getApplicationContext() {return ServiceLocator.context;}
5、增加getInstance()方法
6、增加getBean() 方法
public static ServiceLocator getInstance() {if (servlocator == null)servlocator = (ServiceLocator) context.getBean("serviceLocator");return servlocator;}
public Object getBean(String name) {return context.getBean(name);}
7、将原来的方法中对XmppServer.getInstance()的引用替换为 context
public static Object getService(String name) {return context.getBean(name);}
public static UserService getUserService() {return (UserService) context.getBean(USER_SERVICE);}
三、配置文件修改
1、将ServiceManager对XmppServer.getInstance()的引用改为对ServiceLocator.getInstance()
public static Object getService(String name) { return ServiceLocator.getInstance().getBean(name); }
public static UserService getUserService() { return (UserService) ServiceLocator.getInstance().getBean(USER_SERVICE); }
2、配置文件的修改
在spring-config.xml中加入
<bean id="serviceLocator" class="org.androidpn.server.service.ServiceLocator" scope="singleton" />
3、修改spring-config.xml 为 mina-androidpn-config-context.xml 放到spring的扩展文件路径下 WEB-INF\classes\conf\extension
因为在spring的application-context.xml中有这样一句引用:
<import resource="classpath:conf/extension/*-context.xml"/>
四、启动
五、结果
所有的bean都在 ServiceLocator 中可见。
- androidpn server 通过Spring与restful webservice整合
- spring整合cxf实现restful webservice
- Spring整合CXF webservice restful 实例
- Spring整合CXF webservice restful 实例
- webservice与spring整合
- WebService与Spring整合
- 整合androidpn与SSH
- WebService与Spring整合《三》
- WebService与Spring整合《四》
- webservice-cxf-与spring整合
- WebService -Spring与CXF整合
- spring整合cxf 发布restFul风格的webservice
- Restful(二)Spring整合CXF,发布RSETful 风格WebService
- CXF整合Spring通过tomcat发布webservice
- Spring +restful 构造webservice
- Spring +restful 构造webservice
- Spring整合CXF,发布RSETful 风格WebService--编写客户端代码,调用RESTful WebService
- WebService之CXF与Spring的整合
- 打工vahnzjkl
- 数据库连接池,线程池,C3P0
- xmmintrin.h文件解析
- crontab 用法
- 内联函数 与 成员函数
- androidpn server 通过Spring与restful webservice整合
- 文件导入sdcard下报错,Read-only file system
- Chrome开发,debug的使用方法
- session cookie
- 显示 Sql Server 中所有表中的信息
- 真正的communication
- android 2.3 popwindow NullPointerException的解决
- >>> FilterDispatcher <<< is deprecated!
- 10gocm->session4->数据仓库