废话不说,直接上代码
新增cxf的plugin
CXFPlugin
package com.jfinal.plugin.spring;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.transport.servlet.ServletTransportFactory;
import org.springframework.context.ApplicationContext;
import com.jfinal.plugin.IPlugin;
public class CXFPlugin implements IPlugin{
private ApplicationContext ctx;
SpringBusFactory busFactory;
ServletTransportFactory transportFac;
public boolean start() {
if (ctx == null){
ctx = IocInterceptor.ctx;
}
busFactory = new SpringBusFactory(ctx);
Bus bus = busFactory.createBus();
transportFac = new ServletTransportFactory(bus);
CXFContext.cxf = new CXFContext(ctx,busFactory,transportFac);
return true;
}
public boolean stop() {
return true;
}
}
因为要用到spring的context,所以包名就放在spring同目录了
新增CXFcontent
package com.jfinal.plugin.spring;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.transport.servlet.ServletTransportFactory;
import org.springframework.context.ApplicationContext;
public class CXFContext{
private ApplicationContext ctx;
private SpringBusFactory busFactory;
private ServletTransportFactory transportFac;
static CXFContext cxf;
public static CXFContext getCXFContent(){
return cxf;
}
CXFContext(ApplicationContext ctx,SpringBusFactory busFactory,ServletTransportFactory transportFac){
this.ctx = ctx;
this.busFactory = busFactory;
this.transportFac = transportFac;
}
public ApplicationContext getCtx() {
return ctx;
}
public void setCtx(ApplicationContext ctx) {
this.ctx = ctx;
}
public SpringBusFactory getBusFactory() {
return busFactory;
}
public void setBusFactory(SpringBusFactory busFactory) {
this.busFactory = busFactory;
}
public ServletTransportFactory getTransportFac() {
return transportFac;
}
public void setTransportFac(ServletTransportFactory transportFac) {
this.transportFac = transportFac;
}
public CXFContext getCxf() {
return cxf;
}
public void setCxf(CXFContext cxf) {
this.cxf = cxf;
}
}
新增servlet一个,用于替换CXFServlet
package cn.edu.jxut.common.config;
import java.io.IOException;
import java.io.InputStream;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.cxf.bus.spring.BusApplicationContext;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.resource.ResourceManager;
import org.apache.cxf.resource.URIResolver;
import org.apache.cxf.transport.servlet.AbstractCXFServlet;
import org.apache.cxf.transport.servlet.ServletContextResourceResolver;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.io.InputStreamResource;
import com.jfinal.plugin.spring.CXFContext;
public class WsController extends AbstractCXFServlet{
private GenericApplicationContext childCtx;
private boolean inRefresh;
public void loadBus(ServletConfig servletConfig) throws ServletException {
String springCls = "org.springframework.context.ApplicationContext";
try {
ClassLoaderUtils.loadClass(springCls, getClass());
loadSpringBus(servletConfig);
} catch (ClassNotFoundException e) {
throw new ServletException("Can't load bus with Spring context class", e);
}
}
private void loadSpringBus(ServletConfig servletConfig)
throws ServletException
{
ServletContext svCtx = getServletContext();
ApplicationContext ctx = CXFContext.getCXFContent().getCtx();
if (ctx == null) {
Object ctxObject = svCtx.getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
if ((ctxObject instanceof ApplicationContext)) {
ctx = (ApplicationContext)ctxObject;
} else if (ctxObject != null)
{
Exception ex = (Exception)ctxObject;
throw new ServletException(ex);
}
}
updateContext(servletConfig, ctx);
}
private void updateContext(ServletConfig servletConfig, ApplicationContext ctx)
{
if (ctx == null) {
this.bus = new SpringBusFactory().createBus();
ctx = (ApplicationContext)this.bus.getExtension(BusApplicationContext.class);
} else {
this.bus = CXFContext.getCXFContent().getBusFactory().createBus();
}
ResourceManager resourceManager = (ResourceManager)this.bus.getExtension(ResourceManager.class);
resourceManager.addResourceResolver(new ServletContextResourceResolver(servletConfig.getServletContext()));
replaceDestinationFactory();
this.controller = createServletController(servletConfig);
loadAdditionalConfig(ctx, servletConfig);
}
private void loadAdditionalConfig(ApplicationContext ctx, ServletConfig servletConfig)
{
String location = servletConfig.getInitParameter("config-location");
if (location == null) {
location = "/META-INF/cxf/cxf-servlet.xml";
}
InputStream is = null;
try {
is = servletConfig.getServletContext().getResourceAsStream(location);
if ((is == null) || (is.available() == -1)) {
URIResolver resolver = new URIResolver(location);
if (resolver.isResolved()) {
is = resolver.getInputStream();
}
}
}
catch (IOException e)
{
}
if (is != null) {
this.childCtx = new GenericApplicationContext(ctx);
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.childCtx);
reader.setValidationMode(3);
reader.loadBeanDefinitions(new InputStreamResource(is, location));
this.childCtx.refresh();
}
}
}
web.xml配置:
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
[color=red]cn.edu.jxut.common.config.WsController [/color] </servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
jfinal配置:
public void configHandler(Handlers me) {
me.add(new UrlSkipHandler(".*/service.*",false));
}
此服务已发布可用,在webservice实现类中直接使用jfinal的db获取数据或保存数据都非常方便。
分享到:
相关推荐
使用JFinal集成Ueditor编辑器快速实现增删改查,文章详情页查看等操作,JFInal入门学习Demo,精品demo
使用springboot+JFinal中的Db + Record模式+mysql构建项目,方便快捷,容易上手
jfinal 3.0以上 集成shiro 的jar 包组合,放心下载使用,实测可以完成集成以及权限拦截
jfinal3.4集成shiro,有建表sql,适合刚接触jfinal的萌新
驰骋工作流+驰骋表单引擎+JFinal集成版.您可以使用jfinal的敏捷开发,又可以使用驰骋BPM流程开发平台.
JFinalOA管理系统,集成了企业经常使用的activiti工作流引擎,采用Maven环境构建,编译即可使用,集成了官方的在线编辑器,通过在线编译器即可完成流程的定义。
作为没用过工作流的一员,之前看过vue引入activiti工作流的案例,但是组件中存在很多问题,这个是我修改过并且成功调用,大家可以供参考,富含Java代码(Jfinal),后续出spring版本的, 前台版本vue4.0版本, ...
jfinal demo 程序,使用bootstrap 本人编写的多款插件,如使用coffeescript-maven-plugin编译coffeescript代码,使用lesscsss-maven-plugin编译lesscss代码,使用flyway-maven-plugin运行数据库脚本,支持多种定制...
jfinal 整合 activiti 项目 亲测没有问题,有需要的 可以来下载试试啊
jfinal帮助文档、pdf文档及API文档 大全,中文pdf高清文档
为了更好的服务国内开发者,jfinal与jflow携手开发一版jfinal-jflow版本的工作流程引擎,您可以使用jfianl的简介的语法,高速的性能,同是也能使用上符合中国国情的开源工作流引擎jflow. 驰骋工作流+驰骋表单引擎+...
jfinal3.3整合layui做增删改查 没有做权限等,界面美观。
NULL 博文链接:https://fengzgxing.iteye.com/blog/1884466
JFinal集成Shiro插件,实现登录安全,权限控制等。。。。
jfinal-weixin jfinal 微信支付快发开发jar包
前提:明白JFinal才能看懂这个 使用的是Mysql数据库 直接导入项目,修改JFinal.properties里面的数据库连接 然后把db里面的sql文件执行 ...个人觉得Snake比较用的不爽,然后果断抛弃了 这里只是给做个笔记
jfinal
JFinal_Blog是基于JFinal1.5开源系统搭建的博客系统,以91zcm.com 网站作为模板和演示demo,目前已经加入了OSC开源项目和Github。 一、V2.0 版本新增功能点及bug修复情况: 1、添加百度Ping服务; 2、添加百度...
JFINAL的文档 来自jfinal官网 2016-3-24
jfinal