春化雨 2023-04-07 14:30 采纳率: 0%
浏览 16

添加Aspect切面日志AopLog.java代码报错,如何解决?

添加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

  • 写回答

3条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-04-08 17:56
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

问题事件

  • 创建了问题 4月7日

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致