NutzCN Logo
问答 按照社区超的最简单的slog自定义的注解美誉生效
发布于 932天前 作者 qq_2ac473ac 1158 次浏览 复制 上一个帖子 下一个帖子
标签:
package com.fqx.xactivation.token;

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME) // 必须带这个,不然读取不到的
@Target({ElementType.METHOD}) // aop,一般指方法
@Documented // 记录到javadoc
public @interface Slog {
}



package com.fqx.xactivation.token;

import org.nutz.aop.InterceptorChain;
import org.nutz.aop.MethodInterceptor;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.aop.SimpleAopMaker;
import org.nutz.log.Log;
import org.nutz.log.Logs;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;

public class DemoAopLoader extends SimpleAopMaker<Slog> {

    public List<? extends MethodInterceptor> makeIt(Slog sysLog, Method method, Ioc ioc) {
        return Arrays.asList(new SysLogMethodInterceptor());
    }
}

class SysLogMethodInterceptor implements MethodInterceptor {
    private static final Log log = Logs.get();
    @Override
    public void filter(final InterceptorChain chain) throws Throwable {
        log.debug("hi");
        chain.doChain(); // 继续下一个拦截器, 如果要终止执行,不调用该方法即可
        log.debug("byte");
    }


}

package com.fqx.xactivation;

import org.nutz.integration.shiro.ShiroSessionProvider;
import org.nutz.mvc.annotation.ChainBy;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Modules;
import org.nutz.mvc.annotation.SessionBy;
import org.nutz.mvc.annotation.SetupBy;
import org.nutz.mvc.ioc.provider.ComboIocProvider;

@ChainBy(args="mvc/nutzbook-mvc-chain.js")
@SetupBy(value=MainSetup.class)
@IocBy(type=ComboIocProvider.class, args={"*js", "ioc/",
                                           "*anno", "com.fqx.xactivation",
                                           "*tx", // 事务拦截 aop
                                           "*async",
                                            "*com.fqx.xactivation.token.DemoAopLoader"
                                           }) // 异步执行aop
@Modules(scanPackage=true)
@SessionBy(ShiroSessionProvider.class)
public class MainModule {

}

2022-03-21 15:51:51,811 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:103) DEBUG - Found mapping for [POST] path=/active/getAllDevives : AtiveModule.getAllDevives(AtiveModule.java:87)
2022-03-21 15:51:51,811 com.fqx.xactivation.MyLogTimeProcessor.process(MyLogTimeProcessor.java:18) DEBUG - 日志系统
2022-03-21 15:51:51,833 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:166) DEBUG - Get 'ativeModule'<class com.fqx.xactivation.module.AtiveModule>
2022-03-21 15:51:51,833 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:192) DEBUG - 	 >> Load definition name=ativeModule
2022-03-21 15:51:51,834 org.nutz.ioc.loader.combo.ComboIocLoader.printFoundIocBean(ComboIocLoader.java:226) DEBUG - Found IocObject(ativeModule) in AnnotationIocLoader(packages=[com.fqx.xactivation])
2022-03-21 15:51:51,835 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:223) DEBUG - 	 >> Make...'ativeModule'<class com.fqx.xactivation.module.AtiveModule>
2022-03-21 15:51:51,836 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:65) DEBUG - Save object 'ativeModule' to [app] 
2022-03-21 15:51:51,855 org.nutz.ioc.impl.ScopeContext.remove(ScopeContext.java:85) DEBUG - Remove object 'ativeModule' from [app] 
2022-03-21 15:51:51,856 com.fqx.xactivation.MyLogTimeProcessor.process(MyLogTimeProcessor.java:24) DEBUG - [POST]URI=/xactivation/active/getAllDevives 45ms
2022-03-21 15:51:51,857 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN  - Error@/active/getAllDevives :
org.nutz.ioc.IocException: IocBean[ativeModule] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:153)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
	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.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.fqx.xactivation.MyLogTimeProcessor.process(MyLogTimeProcessor.java:19)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:56)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:450)
	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:387)
	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:189)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:889)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodError: java.lang.invoke.MethodHandles$Lookup.defineClass([B)Ljava/lang/Class;
	at org.nutz.lang.reflect.ReflectTool.defineClass(ReflectTool.java:74)
	at org.nutz.lang.reflect.ReflectTool.defineClass(ReflectTool.java:66)
	at org.nutz.aop.DefaultClassDefiner.define(DefaultClassDefiner.java:25)
	at org.nutz.aop.asm.AsmClassAgent.generate(AsmClassAgent.java:35)
	at org.nutz.aop.AbstractClassAgent.define(AbstractClassAgent.java:56)
	at org.nutz.aop.AbstractClassAgent.define(AbstractClassAgent.java:43)
	at org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:95)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:101)
	... 49 more

搞不懂是哪儿出问题了,再DemoAopLoader 加上iocbean也不行

5 回复

jdk多少呢?

1.8,检查了一下maven编译的是1.7,修改了去看看!
Iocbean(name="$aop_xx")里面这个$符号有什么含义啊

aop拦截器的特殊标识

我把版本弄到1.8了还是报错这个啊,是怎么回事啊

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
  </properties>

jdk弄到12就不报错了。。。

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