修正思路:不让openfire的pluginServlet自动加载类springmvc的DispatcherServlet改成在插件初始化的时候手动将DispatcherServlet注册到PluginServlet中.
1.web-custom.xml不定义DispatcherServlet.
2.自定义一个CustomDispatcherServlet,继承DispatcherServlet,在其构造方法中指定springMvc的配置文件路径,并且修改 配置文件中velocityConfigurer节点下的resourceLoaderPath值.
import java.io.File;
import org.springframework.web.servlet.DispatcherServlet;
import com.aomaisoft.openfire.plugin.usionmrg.web.tools.XMLEditor;
/**
* 自定义DispatcherServlet,指定context位置
*
* @author 20005
* @createDate 2014-7-14 上午11:10:59
*/
public class CustomDispatcherServlet extends DispatcherServlet {
private static final long serialVersionUID = 5713165491251313468L;
public CustomDispatcherServlet() {
super();
String pluginDir = null;
Character fileSep = File.separatorChar;
String contextConfigLocation = pluginDir + fileSep + "java" + fileSep
+ "PluginServlet-servlet.xml";
// 更改模板目录
XMLEditor.alterXML(pluginDir, contextConfigLocation);
contextConfigLocation = "file:/" + contextConfigLocation;
super.setContextConfigLocation(contextConfigLocation);
}
}
附上XMLEditor代码 ,依赖dom4j.jar,可以到 http://www.java2s.com/去下载
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
/**
* xml节点修改
*
* @author 20005
* @createDate 2014-7-15 下午04:35:47
*/
public class XMLEditor {
public static Document read(String fileName) {
SAXReader reader = new SAXReader();
Map<String, String> nsMap = new HashMap<String, String>();
nsMap.put("beans", "http://www.springframework.org/schema/beans");
reader.getDocumentFactory().setXPathNamespaceURIs(nsMap);
reader.setEncoding("UTF-8");
Document document = null;
try {
document = reader.read(new File(fileName));
} catch (DocumentException e) {
e.printStackTrace();
}
return document;
}
public static void alterXML(String newValue, String url) {
OutputFormat format = new OutputFormat("\t", true);
format.setEncoding("UTF-8");
Document document = read(url);
Element node = ((Element) document
.selectSingleNode("//beans:property[@name='resourceLoaderPath']"))
.element("value");
<span style="white-space:pre"> </span>//此处路径要做相应的修改,为你的模板路径
String string = "file:/%s\\web\\WEB-INF\\template";
string = String.format(string, newValue);
node.setText(string);
try {
// 重新写入到XML文档
XMLWriter writer = new XMLWriter(new FileOutputStream(url), format);
writer.write(document);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
3.在插件初始化时手动注册到PluginServlet中
@Override
public void initializePlugin(PluginManager manager, File pluginDirectory) {
// 得到spring mvc配置文件路径,修改成你相应的路径,我是放在web-inf下的
File webXML = new File(pluginDirectory.toString() + File.separatorChar
+ "web" + File.separatorChar + "WEB-INF" + File.separatorChar
+ "springMVC.xml");
// 注册servlet
PluginServlet.registerServlets(manager, this, webXML);
}
4.完成,测试.
spring配置文件部分代码
<!-- 视图解析 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<!-- 在src目录下新建文件夹template用来存在velocity模板文件 -->
<property name="prefix" value="/" />
<property name="suffix" value=".html" />
<property name="contentType" value="text/html;charset=utf-8"></property>
</bean>
<bean id="velocityConfigurer"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath">
<value><!-- 先不填,在程序中指定 -->
</value>
</property>
<property name="velocityProperties">
<props>
<prop key="input.encoding">
UTF-8
</prop>
<prop key="output.encoding">
UTF-8
</prop>
</props>
</property>
</bean>
分享到:
相关推荐
openfire 3.9.1开发所需的jar包,亲测,完全正常!
经过了近3天的时间终于搞定了openfire3.9.1源码的部署,因为最新的是3.9.1所以和其他的版本多多少少还是有些区别的! 1、下载源码 官网下载:h
Android应用源码开发Demo,主要用于毕业设计学习。
spark+openfire二次开发,包括配置基本插件实现等等
一套即时通讯demo
Openfire+spark+smack xmpp
这是为openfire服务器开发插件的简单demo,参照博客:http://blog.csdn.net/ibm_hoojo/
一个图文讲解的openfire 3.9.3的配置安装,并通过eclipse的方式部署openfire源码进行打包,将打包后的文件发布,运行的全过程
前几年的Android应用源码Demo,主要面向的是学生毕业设计学习。
目的:主要是为了监控Openfire各类message,然后对message body做进一步...局限:因为时间有限,本插件并没有对Openfire message协议进行扩展,都是基于原生的xml协议,因此后续开发还需要进行更加深入的二次开发操作。
XMPP+Openfire4.5.1+Smack4.3.4+MySql,支持手机对手机,手机对PC(Spark)的消息收发
解决Openfire strophejs网站 跨域访问问题,文件中有flXHR.js、strophe.flxhr.js跨域脚本,有个具体实例basic.html供参考
openfire+spark+smack开发流程.pdf
这是一个文档,内容是如何编写Openfire开发插件、部署源码
openfire+smack 4.x+websocket的消息推送服务,
openfire+spark 支持视频的插件 把插件放到 spark 安装目录中openfire+spark 支持视频的插件 把插件放到 spark 安装目录中
openfire第一个插件开发以及源码说明,QQ群:28588322
如意800与openfire配置 如意800+openfire reeyoo+openfire
NULL 博文链接:https://beautyofprogram.iteye.com/blog/772281