![](/img/trans.png)
[英]Spring @Transactional different behavior on Service and non-Service methods?
[英]Spring AOP for non-service Class
我是Spring框架的初學者。 我已經實現了Spring AOP來記錄方法執行時間。 使用來自Internet的一些示例,我將其用於如下所示的Service接口。 但是,如果我將表達式更改為非服務類,則相同的代碼將無法正常工作。 下面給出CXF的配置。
<bean id="xbean" class="com........xServiceImpl" />
<jaxrs:server id="xServiceRS" address="/xRSService">
<jaxrs:serviceBeans>
<ref bean="xbean" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="performanceLoggingAdvice" class="com......PerformanceLoggingAdvice" />
<aop:config>
<aop:pointcut id="performanceLoggingPointcut"
expression="execution(* com.....xService.*(..))" />
<aop:advisor advice-ref="performanceLoggingAdvice"
pointcut-ref="performanceLoggingPointcut" id="performanceLoggingInterceptorAdvisor" />
</aop:config>
我已經在堆棧溢出中搜索了類似的問題,但是我沒有得到關於該問題的有用且具體的答案。 知道可能是什么問題嗎? 如何使其適用於非服務類(例如Utils.java)?
在此先感謝您的幫助。
Spring AOP建議僅適用於聲明為Spring bean的類的實例。 使您的Util
類成為Spring bean,使用適當的切入點,它應該可以工作。
在這種情況下,您應該僅通過Spring應用程序上下文(通過調用ApplicationContext.getBean
方法之一)獲得Util
實例,而不是通過使用new
調用構造函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.