jfinal3.2可以和spring整合吗?

jfinal3.2可以和spring整合吗?

评论区

JFinal

2017-08-09 11:22

添加一个拦截即可整合,老版本 jfinal 曾经提供过整合,可以参考一下 jfinal 1.9的实现:http://git.oschina.net/jfinal/jfinal/tree/jfinal-1.9/src/com/jfinal/plugin/spring

注意:新版本 jfinal 的 ActionInvocation 改为了 Invocation,所以这份代码要稍微改一点点才可以使用

大狗哥

2017-08-09 11:39

只是想在工作流模块拦截到spring

JFinal

2017-08-09 11:42

@大狗哥 在 jfinal 的控制层,为 controller 注入 service 层以后,剩下的玩法与你之前的积累就一样了, just do it

阿帕奇

2017-12-21 10:04

@JFinal 感谢波总,我复制了spring的代码过来成功了

JFinal

2017-12-21 13:01

@阿帕奇 jfinal 3.3 发布以后,最好的整合方式是通过扩展一个 ControllerFactory 出来,接管 controller 的创建,然后对创建出来的 controller 进行注入动作,这里是一个实际的项目:
https://gitee.com/duaicxx/Ioc_Manager/tree/3.3.1/src/main/java/org/dval/controllerfactory

我将实际的代码也贴在下面:
public class IocControllerFactory extends ControllerFactory {
public Controller getController(Class controllerClass) throws InstantiationException, IllegalAccessException {
Object target = super.getController(controllerClass);
InjectUtils.inject(target);
return (Controller) target;
}
}

有了上面的代码后,配置一下 ControllerFactory 即可:
me.setControllerFactory(new IocControllerFactory ());

用拦截器整合 spring 用到的拦截器,可以被 @Clear 注解清除掉,所以没有上面这个办法好

阿帕奇

2018-01-02 10:34

@JFinal 感谢波总的解答,但是我用了上面的方法后,出现了一个问题,就是在iockit里面的beanMap报空指针,我想问一下,这个beanMap怎么初始化?下面是错误代码2018-01-02 10:12:32
[ERROR]-[Thread: qtp294184992-19]-[com.jfinal.core.ActionHandler.handle()]: /
java.lang.NullPointerException
at com.zhougao.demo.consumer.controllerFactory.ioc.IocKit.getBean(IocKit.java:32)
at com.zhougao.demo.consumer.controllerFactory.ioc.InjectUtils.inject(InjectUtils.java:50)
at com.zhougao.demo.consumer.controllerFactory.ioc.InjectUtils.inject(InjectUtils.java:23)
at com.zhougao.demo.consumer.controllerFactory.IocControllerFactory.getController(IocControllerFactory.java:41)
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:78)
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:365)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Unknown Source)