gpt4 book ai didi

java - Spring aop表达式

转载 作者:太空宇宙 更新时间:2023-11-04 11:18:54 25 4
gpt4 key购买 nike

这是applicationContext.xml AOP 部分:

<bean id="logHandler" class="demo.anderson.aop.LogHandler"></bean>
<aop:config>
<aop:aspect id="log" ref="logHandler">
<aop:pointcut id="addLog" expression="execution(* demo.anderson.controller.StudentController.*(..)) || execution(* demo.anderson.controller.ScoreController.*(..))" />
<aop:before method="beforeLog" pointcut-ref="addLog" />
<aop:after method="afterLog" pointcut-ref="addLog" />
</aop:aspect>
</aop:config>

它正在工作!

但是当我像这样配置 aop:pointcut 时:

<aop:pointcut id="addLog" expression="execution(* demo.anderson.controller.*.*(..))"  />

它坏了:

18-Jul-2017 11:06:39.416 嚴重 [http-nio-8090-exec-71] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Expected raw type form of org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$Match ............................................................. Caused by: java.lang.IllegalStateException: Expected raw type form of org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$Match .............................................................

18-Jul-2017 11:06:39.434 資訊 [http-nio-8090-exec-71] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext

有人能告诉我为什么吗?正确的配置是什么?

最佳答案

<aop:pointcut id="addLog" expression="execution(* demo.anderson.controller..*.*(..))"  /> 

引用自 spring 文档。

https://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html

执行服务包或子包中定义的任何方法:

执行(* com.xyz.service..*.*(..))

关于java - Spring aop表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45156991/

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