NutzCN Logo
问答 为什么我的Slog用的是原来的SlogService而不是我自己写的?
发布于 2793天前 作者 LovelyIsJustice 2169 次浏览 复制 上一个帖子 下一个帖子
标签:

想请教一下,在哪里控制他是是用我自己写的SlogService

18 回复

取的ioc bean的名称叫 syslogService, 只要你的类的ioc name也是命名一样,就能覆盖

@IocBean(name="slogService")

@wendal
我是不是把@IocBean(name="slogService") 写在SlogAopInterceptor的类头上

@IocBean(name="slogService")
public class SlogAopInterceptor implements MethodInterceptor {

但是报错了

org.nutz.ioc.IocException: [slogService] # FAIL to create Ioc Bean name=[slogService]
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
	at org.nutz.plugins.slog.aop.SlogAopInterceptor.doLog(SlogAopInterceptor.java:81)
	at org.nutz.plugins.slog.aop.SlogAopInterceptor.filter(SlogAopInterceptor.java:70)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at cn.kmia.bas.controllers.PassengerAction$$NUTZAOP.addPas(PassengerAction.java:1)
	at cn.kmia.bas.controllers.PassengerAction$$FASTCLASS._invoke(PassengerAction.java:1)
	at org.nutz.lang.reflect.AbstractFastClass.invoke(AbstractFastClass.java:143)
	at org.nutz.lang.reflect.FastClassFactory.invoke(FastClassFactory.java:67)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.integration.shiro.NutShiroProcessor.process(NutShiroProcessor.java:126)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1437)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.lang.born.BorningException: Fail to born 'cn.kmia.bas.common.services.log.aop.SlogAopInterceptor'
 by args: [] because: No suitable Constructor or Factory Method!!
	at org.nutz.lang.Mirror.getBorning(Mirror.java:954)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:107)
	... 58 more

SlogAopInterceptor标个slogService,能不死吗?

"我自己写的SlogService", 把@IocBean表在它上面啊

我是这样写的

@IocBean(name="slogService")
public class SlogService {
    private static final Log log = Logs.get();

然后报错了

[WARN ] 2017-03-31 16:10:06,281 org.nutz.mvc.impl.processor.FailProcessor Error@/view/best/addPas :
java.lang.ClassCastException: cn.kmia.bas.common.services.log.service.SlogService$$NUTZAOP cannot be cast to org.nutz.plugins.slog.service.SlogService
	at org.nutz.plugins.slog.aop.SlogAopInterceptor.doLog(SlogAopInterceptor.java:81)
	at org.nutz.plugins.slog.aop.SlogAopInterceptor.filter(SlogAopInterceptor.java:70)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at cn.kmia.bas.controllers.PassengerAction$$NUTZAOP.addPas(PassengerAction.java:1)
	at cn.kmia.bas.controllers.PassengerAction$$FASTCLASS._invoke(PassengerAction.java:1)
	at org.nutz.lang.reflect.AbstractFastClass.invoke(AbstractFastClass.java:143)
	at org.nutz.lang.reflect.FastClassFactory.invoke(FastClassFactory.java:67)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.integration.shiro.NutShiroProcessor.process(NutShiroProcessor.java:126)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1437)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

你得继承原本的SlogService

@wendal
兽总,昨天我根据您的指导配了一下,因为数据量比较小,不需要他分月建表和查询,就直接新建了一个slogBean,然后直接用了dao进行插入数据库,但是现在就无法记录日志,报错

[DEBUG] 2017-04-01 10:07:49,019       org.nutz.ioc.impl.NutIoc Get 'slogService'<class org.nutz.plugins.slog.service.SlogService>
[DEBUG] 2017-04-01 10:07:49,019       org.nutz.ioc.impl.NutIoc 	 >> Load definition name=slogService
[DEBUG] 2017-04-01 10:07:49,019 org.nutz.ioc.loader.combo.ComboIocLoader Found IocObject(slogService) in AnnotationIocLoader(packages=[cn.kmia.bas])
[DEBUG] 2017-04-01 10:07:49,019       org.nutz.ioc.impl.NutIoc 	 >> Make...'slogService'<class org.nutz.plugins.slog.service.SlogService>
[DEBUG] 2017-04-01 10:07:49,025 org.nutz.ioc.impl.ScopeContext Save object 'slogService' to [app] 
[DEBUG] 2017-04-01 10:07:49,026 org.nutz.ioc.val.ReferTypeValue name=basicDao not found, search for type=cn.kmia.bas.dao.BaseDao
[DEBUG] 2017-04-01 10:07:49,026       org.nutz.ioc.impl.NutIoc Get 'baseDao'<class cn.kmia.bas.dao.BaseDao>
[DEBUG] 2017-04-01 10:07:49,027 org.nutz.plugins.slog.aop.SlogAopInterceptor slog fail

不知道什么原因

debug一下SlogAopInterceptor

@wendal
没有走到。。像是没有运行这个SlogAopInterceptor一样。。是不是他又是运行的jar包里面的?

什么没走到?SlogAopInterceptor的日志都出来了

@wendal
就是我在

public SlogAopInterceptor(Ioc ioc, Slog slog, Method method)
public void filter(InterceptorChain chain) throws Throwable 

下的第一句话都打了断点,但是程序并没有在这两个断点处停下

@lovelyisjustice 走的是插件里面的类吧?

@wendal
应该是的。。没有走我自己写的这个SlogAopInterceptor

你是整个改了?那插件删掉呗

@wendal
额。好吧。。应该是我从最开始就想错了。。我只是想自定义获取userId然后想让所有日志都写在一个表里。。是不是只用重新slogservice就行了?

@wendal
那再麻烦一下兽总,自定义获取userId是写在哪里,是不是写在扩展的slogservice里?

能不能先通读一下SlogService类,然后按需要改

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