改了一些代码,启动时有个INFO的提示,虽说是INFO提示,但以前没见过;
2017-09-27 09:49:46,982 INFO (o.s.a.f.CglibAopProxy:) - Final method [private final void xxxx.xxx.AbstractDalService.baseValid(xxx.xxx.BasicDto)] cannot get proxied via CGLIB: Calls to this method will NOT be routed to the target instance and might lead to NPEs against uninitialized fields in the proxy instance.
于是打开CglibAopProxy类,看了一下原因;
/** * Checks for final methods on the given {@code Class}, as well as package-visible * methods across ClassLoaders, and writes warnings to the log for each one found. */ private void doValidateClass(Class proxySuperClass, ClassLoader proxyClassLoader, Set> ifcs) { if (proxySuperClass != Object.class) { Method[] methods = proxySuperClass.getDeclaredMethods(); for (Method method : methods) { int mod = method.getModifiers(); if (!Modifier.isStatic(mod)) { if (Modifier.isFinal(mod)) { if (implementsInterface(method, ifcs)) { logger.warn("Unable to proxy interface-implementing method [" + method + "] because " + "it is marked as final: Consider using interface-based JDK proxies instead!"); } logger.info("Final method [" + method + "] cannot get proxied via CGLIB: " + "Calls to this method will NOT be routed to the target instance and " + "might lead to NPEs against uninitialized fields in the proxy instance."); } else if (!Modifier.isPublic(mod) && !Modifier.isProtected(mod) && !Modifier.isPrivate(mod) && proxyClassLoader != null && proxySuperClass.getClassLoader() != proxyClassLoader) { logger.info("Method [" + method + "] is package-visible across different ClassLoaders " + "and cannot get proxied via CGLIB: Declare this method as public or protected " + "if you need to support invocations through the proxy."); } } } doValidateClass(proxySuperClass.getSuperclass(), proxyClassLoader, ifcs); } }
这就好改了嘛,将AbstractDalService.baseValid方法改成 static的就ok了,提示消失;
TODO
下来仔细分析一下,由其是AOP那么事;