gpt4 book ai didi

java - 我们可以禁用 AOP 调用吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:53:06 26 4
gpt4 key购买 nike

我有基于 AOP 的登录功能,具有以下设置

上下文xml配置:

<bean id="performanceMonitor" 
class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor" />

<aop:config>
<aop:pointcut id="allServiceMethods"
expression="execution(* com.eshop.sfweb.service.impl..*(..))" />
<aop:pointcut id="allEpServices"
expression="execution(* com.service.catalog..*(..))" />
<aop:advisor pointcut-ref="allServiceMethods"
advice-ref="performanceMonitor" order="2" />
<aop:advisor pointcut-ref="allEpServices"
advice-ref="performanceMonitor" order="2" />
</aop:config>

Log4j 属性:

log4j.logger.org.springframework.aop.interceptor.PerformanceMonitorIntercept
or=${ep.perflog.level},PERFORMANCE
log4j.appender.PERFORMANCE.File=webAppRoot:WEB-INF/log/performance.log
log4j.appender.PERFORMANCE.threshold=DEBUG
log4j.appender.PERFORMANCE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.PERFORMANCE.DatePattern='.'yyyy-MM-dd
log4j.appender.PERFORMANCE.layout=org.apache.log4j.PatternLayout
log4j.appender.PERFORMANCE.layout.ConversionPattern=%d -- %-5p [%t | %F:%L]
-- %m%n

有什么方法可以根据环境禁用 AOP 调用本身吗?我可以非常轻松地禁用日志记录,但我可以禁用/启用整个后台进程和调用吗?

如果需要任何说明,请提出。

最佳答案

由于您使用的是 Spring AOP,启用或禁用方面的一种快速方法可能是简单地使用 Bean 配置文件。

定义一个配置文件说 enableAOP:将 aop:config 包装在特定配置文件下的配置文件中

<beans profile="enableAOP">
<aop:config> <aop:pointcut id="allServiceMethods"
expression="execution(* com.eshop.sfweb.service.impl..*(..))" />
<aop:pointcut id="allEpServices" expression="execution(*
com.service.catalog..*(..))" />
....
</beans>

现在,无论您希望启用特定方面的哪个环境,只需运行 enableAOP 配置文件即可。

关于java - 我们可以禁用 AOP 调用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11674545/

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