添加Aspect切面日志AopLog.java代码报错:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'mbeanExporter' defined in class path resource [org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.jmx.export.annotation.AnnotationMBeanExporter]: Factory method 'mbeanExporter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'mbeanServer' defined in class path resource [org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException:
Could not generate CGLIB subclass of class com.sun.jmx.mbeanserver.JmxMBeanServer: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException:
Cannot subclass final class com.sun.jmx.mbeanserver.JmxMBeanServer
Eclipse 4.19.0集成开发环境 SpringBoot+JPA+Themeleaf+Aspect切面日志
尝试过的解决方法
(1)增加于减少pom.xml依赖,还是报错;
(2)将AopLog.java代码去掉,程序运行正常。进一步排查发现是
@Pointcut("execution(public * com.user.controller...(..))")包路径的设置问题com.user.controller...(..)需要根据包的实际路径设置,否则报错
我想要达到的结果
14:04:29.560 [restartedMain] INFO com.user.ThymeleafTestApplication - Starting ThymeleafTestApplication using Java 15 on mythinkbook with PID 46596 (D:\tool\workspace\JPAUserDemo\target\classes started by $ong in D:\tool\workspace\JPAUserDemo)
14:04:29.561 [restartedMain] INFO com.user.ThymeleafTestApplication - No active profile set, falling back to default profiles: default
14:04:29.590 [restartedMain] INFO o.s.b.d.e.DevToolsPropertyDefaultsPostProcessor - Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
14:04:29.591 [restartedMain] INFO o.s.b.d.e.DevToolsPropertyDefaultsPostProcessor - For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
14:04:30.033 [restartedMain] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data JPA repositories in DEFAULT mode.
14:04:30.076 [restartedMain] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 36 ms. Found 1 JPA repository interfaces.
14:04:30.717 [restartedMain] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 9000 (http)
14:04:30.724 [restartedMain] INFO o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-9000"]
14:04:30.724 [restartedMain] INFO o.a.catalina.core.StandardService - Starting service [Tomcat]
14:04:30.724 [restartedMain] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.55]
14:04:30.813 [restartedMain] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
14:04:30.813 [restartedMain] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 1222 ms
14:25:45.714 [http-nio-9000-exec-2] INFO com.user.aop.AopLog - 应答值:redirect:/list
14:25:45.714 [http-nio-9000-exec-2] INFO com.user.aop.AopLog - 费时:0
14:25:45.732 [http-nio-9000-exec-3] INFO com.user.aop.AopLog - URL:/list
14:25:45.732 [http-nio-9000-exec-3] INFO com.user.aop.AopLog - HTTP方法:GET
14:25:45.732 [http-nio-9000-exec-3] INFO com.user.aop.AopLog - IP地址:0:0:0:0:0:0:0:1
14:25:45.732 [http-nio-9000-exec-3] INFO com.user.aop.AopLog - 类的方法:com.user.controller.UserController.list
14:25:45.732 [http-nio-9000-exec-3] INFO com.user.aop.AopLog - 参数:null
Hibernate: select user0_.id as id1_0_, user0_.address as address2_0_, user0_.age as age3_0_, user0_.birthday as birthday4_0_, user0_.des as des5_0_, user0_.password as password6_0_, user0_.phone as phone7_0_, user0_.sex as sex8_0_, user0_.user_name as user_nam9_0_ from user user0_
Hibernate: select user0_.id as id1_0_, user0_.address as address2_0_, user0_.age as age3_0_, user0_.birthday as birthday4_0_, user0_.des as des5_0_, user0_.password as password6_0_, user0_.phone as phone7_0_, user0_.sex as sex8_0_, user0_.user_name as user_nam9_0_ from user user0_
14:25:45.767 [http-nio-9000-exec-1] INFO com.user.aop.AopLog - 应答值:user/list
14:25:45.767 [http-nio-9000-exec-3] INFO com.user.aop.AopLog - 应答值:user/list
14:25:45.767 [http-nio-9000-exec-1] INFO com.user.aop.AopLog - 费时:127
14:25:45.767 [http-nio-9000-exec-3] INFO com.user.aop.AopLog - 费时:35