NutzCN Logo
问答 关于nutzwk的插件问题
发布于 2858天前 作者 老司机 2225 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

nutzwk中所说的插件,其实是项目中某个接口的实现类???
然后在

pluginMaster.register(code, plugin, args);

注册后,我怎么调用这个类?怎么把这个类交给ioc管理?

12 回复

test 下面不是有个写好的插件demo么

@Wizzercn 看到logDEBUG - TestPlugin::插件安装成功后执行的方法,初始化资源
然后怎么调用TestPlugin啊?拦截方法?怎么拦截?

@wendal 看到logDEBUG - TestPlugin::插件安装成功后执行的方法,初始化资源
然后怎么调用TestPlugin啊?拦截方法?怎么拦截?

它拦截的已有的方法

@wendal 我看到TestPlugin有这样的注解

@SPlugin(value="first",method="list")

然后我在controller里面自建了一个,list方法,但当访问到list方法的时候并没有触发TestPlugin的beforeInvoke和afterInvoke方法,why?

来自炫酷的 NutzCN

在list方法内,打印一下堆栈信息看看

@wendal list定义在SysApiController下

 @At
    public void list() {
        Throwable ex = new Throwable();
        StackTraceElement[] stackElements = ex.getStackTrace();
        if (stackElements != null) {
            for (int i = 0; i < stackElements.length; i++) {
                System.out.print(stackElements[i].getClassName() + "/t");
                System.out.print(stackElements[i].getFileName() + "/t");
                System.out.print(stackElements[i].getLineNumber() + "/t");
                System.out.println(stackElements[i].getMethodName());
                System.out.println("-----------------------------------");
            }
        }
    }

打印出来

cn.wizzer.modules.controllers.platform.sys.SysApiController/tSysApiController.java/t35/tlist
-----------------------------------
cn.wizzer.modules.controllers.platform.sys.SysApiController$$FASTCLASS/tSysApiController.java/t1/t_invoke
-----------------------------------
org.nutz.lang.reflect.AbstractFastClass/tAbstractFastClass.java/t143/tinvoke
-----------------------------------
org.nutz.lang.reflect.FastClassFactory/tFastClassFactory.java/t67/tinvoke
-----------------------------------
org.nutz.mvc.impl.processor.MethodInvokeProcessor/tMethodInvokeProcessor.java/t27/tprocess
-----------------------------------
org.nutz.mvc.impl.processor.AbstractProcessor/tAbstractProcessor.java/t44/tdoNext
-----------------------------------
org.nutz.mvc.impl.processor.AdaptorProcessor/tAdaptorProcessor.java/t33/tprocess
-----------------------------------
org.nutz.mvc.impl.processor.AbstractProcessor/tAbstractProcessor.java/t44/tdoNext
-----------------------------------
org.nutz.mvc.impl.processor.ActionFiltersProcessor/tActionFiltersProcessor.java/t58/tprocess
-----------------------------------
org.nutz.mvc.impl.processor.AbstractProcessor/tAbstractProcessor.java/t44/tdoNext
-----------------------------------
cn.wizzer.common.processor.XssSqlFilterProcessor/tXssSqlFilterProcessor.java/t35/tprocess
-----------------------------------
org.nutz.mvc.impl.processor.AbstractProcessor/tAbstractProcessor.java/t44/tdoNext
-----------------------------------
cn.wizzer.common.processor.NutShiroProcessor/tNutShiroProcessor.java/t52/tprocess
-----------------------------------
org.nutz.mvc.impl.processor.AbstractProcessor/tAbstractProcessor.java/t44/tdoNext
-----------------------------------
org.nutz.mvc.impl.processor.ModuleProcessor/tModuleProcessor.java/t123/tprocess
-----------------------------------
org.nutz.mvc.impl.processor.AbstractProcessor/tAbstractProcessor.java/t44/tdoNext
-----------------------------------
org.nutz.mvc.impl.processor.EncodingProcessor/tEncodingProcessor.java/t27/tprocess
-----------------------------------
org.nutz.mvc.impl.processor.AbstractProcessor/tAbstractProcessor.java/t44/tdoNext
-----------------------------------
org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor/tUpdateRequestAttributesProcessor.java/t15/tprocess
-----------------------------------
org.nutz.mvc.impl.processor.AbstractProcessor/tAbstractProcessor.java/t44/tdoNext
-----------------------------------
cn.wizzer.common.processor.GlobalsSettingProcessor/tGlobalsSettingProcessor.java/t37/tprocess
-----------------------------------
org.nutz.mvc.impl.processor.AbstractProcessor/tAbstractProcessor.java/t44/tdoNext
-----------------------------------
cn.wizzer.common.processor.LogTimeProcessor/tLogTimeProcessor.java/t21/tprocess
-----------------------------------
org.nutz.mvc.impl.NutActionChain/tNutActionChain.java/t44/tdoChain
-----------------------------------
org.nutz.mvc.impl.ActionInvoker/tActionInvoker.java/t67/tinvoke
-----------------------------------
org.nutz.mvc.ActionHandler/tActionHandler.java/t31/thandle
-----------------------------------
org.nutz.mvc.NutFilter/tNutFilter.java/t198/tdoFilter
-----------------------------------
org.apache.catalina.core.ApplicationFilterChain/tApplicationFilterChain.java/t192/tinternalDoFilter
-----------------------------------
org.apache.catalina.core.ApplicationFilterChain/tApplicationFilterChain.java/t165/tdoFilter
-----------------------------------
cn.wizzer.common.filter.RouteFilter/tRouteFilter.java/t33/tdoFilter
-----------------------------------
org.apache.catalina.core.ApplicationFilterChain/tApplicationFilterChain.java/t192/tinternalDoFilter
-----------------------------------
org.apache.catalina.core.ApplicationFilterChain/tApplicationFilterChain.java/t165/tdoFilter
-----------------------------------
org.apache.shiro.web.servlet.ProxiedFilterChain/tProxiedFilterChain.java/t61/tdoFilter
-----------------------------------
org.apache.shiro.web.servlet.AdviceFilter/tAdviceFilter.java/t108/texecuteChain
-----------------------------------
org.apache.shiro.web.servlet.AdviceFilter/tAdviceFilter.java/t137/tdoFilterInternal
-----------------------------------
org.apache.shiro.web.servlet.OncePerRequestFilter/tOncePerRequestFilter.java/t125/tdoFilter
-----------------------------------
org.apache.shiro.web.servlet.ProxiedFilterChain/tProxiedFilterChain.java/t66/tdoFilter
-----------------------------------
org.apache.shiro.web.servlet.AbstractShiroFilter/tAbstractShiroFilter.java/t449/texecuteChain
-----------------------------------
org.apache.shiro.web.servlet.AbstractShiroFilter$1/tAbstractShiroFilter.java/t365/tcall
-----------------------------------
org.apache.shiro.subject.support.SubjectCallable/tSubjectCallable.java/t90/tdoCall
-----------------------------------
org.apache.shiro.subject.support.SubjectCallable/tSubjectCallable.java/t83/tcall
-----------------------------------
org.apache.shiro.subject.support.DelegatingSubject/tDelegatingSubject.java/t383/texecute
-----------------------------------
org.apache.shiro.web.servlet.AbstractShiroFilter/tAbstractShiroFilter.java/t362/tdoFilterInternal
-----------------------------------
org.apache.shiro.web.servlet.OncePerRequestFilter/tOncePerRequestFilter.java/t125/tdoFilter
-----------------------------------
org.apache.catalina.core.ApplicationFilterChain/tApplicationFilterChain.java/t192/tinternalDoFilter
-----------------------------------
org.apache.catalina.core.ApplicationFilterChain/tApplicationFilterChain.java/t165/tdoFilter
-----------------------------------
org.apache.catalina.core.StandardWrapperValve/tStandardWrapperValve.java/t199/tinvoke
-----------------------------------
org.apache.catalina.core.StandardContextValve/tStandardContextValve.java/t96/tinvoke
-----------------------------------
org.apache.catalina.authenticator.AuthenticatorBase/tAuthenticatorBase.java/t474/tinvoke
-----------------------------------
org.apache.catalina.core.StandardHostValve/tStandardHostValve.java/t140/tinvoke
-----------------------------------
org.apache.catalina.valves.ErrorReportValve/tErrorReportValve.java/t79/tinvoke
-----------------------------------
org.apache.catalina.valves.AbstractAccessLogValve/tAbstractAccessLogValve.java/t624/tinvoke
-----------------------------------
org.apache.catalina.core.StandardEngineValve/tStandardEngineValve.java/t87/tinvoke
-----------------------------------
org.apache.catalina.connector.CoyoteAdapter/tCoyoteAdapter.java/t349/tservice
-----------------------------------
org.apache.coyote.http11.Http11Processor/tHttp11Processor.java/t783/tservice
-----------------------------------
org.apache.coyote.AbstractProcessorLight/tAbstractProcessorLight.java/t66/tprocess
-----------------------------------
org.apache.coyote.AbstractProtocol$ConnectionHandler/tAbstractProtocol.java/t745/tprocess
-----------------------------------
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor/tNioEndpoint.java/t1437/tdoRun
-----------------------------------
org.apache.tomcat.util.net.SocketProcessorBase/tSocketProcessorBase.java/t49/trun
-----------------------------------
java.util.concurrent.ThreadPoolExecutor/tThreadPoolExecutor.java/t1142/trunWorker
-----------------------------------
java.util.concurrent.ThreadPoolExecutor$Worker/tThreadPoolExecutor.java/t617/trun
-----------------------------------
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable/tTaskThread.java/t61/trun
-----------------------------------
java.lang.Thread/tThread.java/t745/trun
-----------------------------------

好奇怪,这个类没有被aop改造

@wendal 这是安装时候的日志

2017-01-25 10:26:55,916 cn.wizzer.common.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [GET ]URI=/platform/home/path 6ms
2017-01-25 10:26:59,207 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) DEBUG - Found mapping for [POST] path=/platform/sys/plugin/enable/7cb0bac3389146538a33b92004cce61c : SysPluginController.enable(SysPluginController.java:108)
2017-01-25 10:26:59,208 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'permission'<class cn.wizzer.common.shiro.view.Permission>
2017-01-25 10:26:59,209 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dateUtil'<class cn.wizzer.common.util.DateUtil>
2017-01-25 10:26:59,209 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'stringUtil'<class cn.wizzer.common.util.StringUtil>
2017-01-25 10:26:59,210 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'sysPluginController'<class cn.wizzer.modules.controllers.platform.sys.SysPluginController>
2017-01-25 10:26:59,218 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM sys_plugin  WHERE id=?
    |                                1 |
    |----------------------------------|
    | 7cb0bac3389146538a33b92004cce61c |
  For example:> "SELECT * FROM sys_plugin  WHERE id='7cb0bac3389146538a33b92004cce61c'"
2017-01-25 10:26:59,225 cn.wizzer.common.plugin.PluginMaster.remove(PluginMaster.java:105) DEBUG - plugin remove : TestPlugin : cn.wizzer.modules.plugins.TestPlugin
2017-01-25 10:26:59,226 cn.wizzer.modules.plugins.TestPlugin.destory(TestPlugin.java:26) DEBUG - TestPlugin::插件卸载时执行的方法,释放资源
2017-01-25 10:26:59,226 cn.wizzer.modules.plugins.TestPlugin.init(TestPlugin.java:20) DEBUG - TestPlugin::插件安装成功后执行的方法,初始化资源
2017-01-25 10:26:59,227 cn.wizzer.common.plugin.PluginMaster.register(PluginMaster.java:47) INFO  - load plugin key=TestPlugin class=cn.wizzer.modules.plugins.TestPlugin
2017-01-25 10:26:59,230 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - UPDATE sys_plugin SET code=?,className=?,args=?,path=?,disabled=?,opBy=?,opAt=?,delFlag=?  WHERE id=?
    |          1 |                                    2 | 3 |                                               4 |     5 |                                6 |          7 |     8 |                                9 |
    |------------|--------------------------------------|--|-------------------------------------------------|-------|----------------------------------|------------|-------|----------------------------------|
    | TestPlugin | cn.wizzer.modules.plugins.TestPlugin |  | /upload/plugin/vlnq2ra1m6j26qmqnecr0tufto.class | false | 814c8873eb034b8f801d89ba1f0c211b | 1485311215 | false | 7cb0bac3389146538a33b92004cce61c |
  For example:> "UPDATE sys_plugin SET code='TestPlugin',className='cn.wizzer.modules.plugins.TestPlugin',args='',path='/upload/plugin/vlnq2ra1m6j26qmqnecr0tufto.class',disabled=false,opBy='814c8873eb034b8f801d89ba1f0c211b',opAt=1485311215,delFlag=false  WHERE id='7cb0bac3389146538a33b92004cce61c'"
2017-01-25 10:26:59,269 cn.wizzer.common.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) DEBUG - [POST]URI=/platform/sys/plugin/enable/7cb0bac3389146538a33b92004cce61c 61ms

得翻一下启动日志,看看SysApiController相关的

关注一下nutzcn的源码哦

添加回复
请先登陆
回到顶部