gpt4 book ai didi

java - Spring AOP中没有这样的方法将切入点应用于批处理作业

转载 作者:行者123 更新时间:2023-12-02 12:42:24 24 4
gpt4 key购买 nike

我正在学习 Spring AOP,并决定使用它来对批处理作业进行一些性能监控。我想在 Spring Batch ItemWriter jdbctemplate 方法中监视 .update() 对象的 write() 方法的执行时间。

我的pom.xml的相关部分:

  <dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.2.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>

我的spring配置XML文件:

<aop:config>
<aop:pointcut id="writerMethods" expression="execution(* my.package.name.writers.IvrWriter.write())"/>
<aop:advisor advice-ref="performanceMonitor" pointcut-ref="writerMethods" order="2"/>
</aop:config>

但是,我收到了 NoSuchMethodError 消息,表明我在理解如何调试方面遇到了一些困难:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.config.ConfigurableBeanFactory.getSingletonMutex()Ljava/lang/Object;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:102)
at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:248)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:880)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:852)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:446)
... 15 more
Caused by: java.lang.NoSuchMethodError: org.springframework.beans.factory.config.ConfigurableBeanFactory.getSingletonMutex()Ljava/lang/Object;
at org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor.resetAdviceMonitor(AbstractBeanFactoryPointcutAdvisor.java:81)
at org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor.setBeanFactory(AbstractBeanFactoryPointcutAdvisor.java:76)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1475)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1443)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 27 more

我什至不确定这是否是 Spring AOP 的依赖问题、我如何编写切入点表达式的语法错误或其他问题。我遵循了访问 enter link description here 的教程,了解如何编写切入点表达式。谁能指导我正确的方向?

最佳答案

来自异常堆栈跟踪:

NoSuchMethodError: org.springframework.beans.factory.config.ConfigurableBeanFactory.getSingletonMutex()Ljava/lang/Object;

您应该将 spring aop afticat 的 pom.xml 版本更新为版本:4.3.9.RELEASE。您对 spting Artifact 使用两个不同的版本 spring-aspects with 3.1.2.RELEASEspring-aop with 4.3.9.RELEASE 它们不兼容

    <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>

更好地使用 pom.xml 中的属性变量

<properties>
<spring.version>4.3.4.RELEASE</spring.version>
</properties>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>

关于java - Spring AOP中没有这样的方法将切入点应用于批处理作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44893072/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com