Found in following leagacy code the expression
<aop:config>
<!-- the execution of any method defined in the 'service' package or a sub-package -->
<aop:pointcut id="apiServicesPointCuts"
expression="execution(* my.example.api..service..*.*(..)) && !execution(* java.lang.Object.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="apiServicesPointCuts" />
</aop:config>
the expression
!execution(* java.lang.Object.*(..)
If I read it correct that means do not match advice on any method withhin the java.lang.Object.
Does that make sense when the advice is for a transaction manager?
I'm using aspectj 1.6.8
Related
I have a spring context xml configuration with AOP point pointcut :
<aop:config>
<aop:pointcut id="allOperation"
expression="execution(* my.services.v2..*Test.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allOperation"/>
</aop:config>
Which supposed to intercept any method in any sub package that ends with Test.
Example of method supposed to be intercepted : my.services.v2.MyServiceTest.getSomeThink()
But it doesn't work, help me please
I've got some trouble while configuring spring transaction manager. The application I'm working on has a layered architecture. Therefore it has a service layer containing all the transactional services. I wanted for spring to rollback the transaction when a checked (application specific) exception has occurred. I succeeded doing that by annotation as follows:
#Transactional(value="transactionDds", rollbackfor="Throwable")
This works fine. But since I've so many services hence I want to move this configuration to XML (spring DAO context file). This is what I've done:
<tx:advice id="txAdvice" transaction-manager="transactionManagerDds">
<tx:attributes>
<tx:method name="*" read-only="false" propagation="REQUIRED" rollback-for="Throwable"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="transRollbackOp" expression="execution(*fr.def.iss.ult.moduleManagement.service.dds.*.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="transRollbackOp"/>
</aop:config>
<bean id="transactionManagerDds" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="beanDataSourceFactory" />
<qualifier value="transactionDds"/>
</bean>
So basically, I'va a transaction manager which is associated to an advice which rolls back for the possible methods when a Throwable exception occurs. And this advice is linked to an AOP config that way we specify all the interfaces in the service layer of application on which this transaction configuration is to be applied. But this doesn't work. Transaction doesn't roll back Throwable exception occurs. I don't understand that this works with annotation but not with declarative configuration in XML.
I'm really looking forward for your suggestions. I'm totally blocked. Plz help me out. Thanx in advance.
<aop:config>
<aop:pointcut id="transRollbackOp" expression="execution(*fr.def.iss.ult.moduleManagement.service.dds.*.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="transRollbackOp"/>
</aop:config>
In your <aop:config /> the expression you entered is invalid. It should at least contain a whitespace between * and fr.def.
Next instead of .*.*.* I suggest writing ..*.* which selects all classes in all subpackages regardless of depth.
In short change your expression to execution(* fr.def.iss.ult.moduleManagement.service.dds..*.*(..)) should make it work.
So I have class C implements interface B and interface B extends interface A.
My aop-config.xml:
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="aMethods" expression="execution(* com.mypackage.A.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="aMethods"/>
</aop:config>
Basically I want for all classes implementing interface A their methods to run in transactional context.
It doesn't seem to work when the pointcut expression is pointing to interface A but it does work if pointing to interface B.
Any thoughts on that?
You have a pointcut for an exact match for type A NOT for subtypes. To include subtypes add a + to the pointcut.
<aop:pointcut id="aMethods" expression="execution(* com.mypackage.A+.*(..))"/>
For more information the AspectJ reference guide. AspectJ in Action 2nd is also a book I can recommend.
I`m trying to get in contact with AOP. Therefore I wrote a little helloworld, but it doesnt work as I want.
Inside the aspect I use the keyword "after", but if the given method is called, the "aspect" - method executes before the joinpoint!?Does anyone know why?
Anything else works fine! (No exceptions!)
<bean id="myAspectBean" class="hello.world.MyAspect">
</bean>
<bean id="helloBean" class="hello.world.Hello">
<property name="first" value="Hello"/>
<property name="second" value="World!"/>
</bean>
<aop:config>
<aop:aspect ref="myAspectBean">
<aop:pointcut id="pc" expression="execution(* sayHello(..))"/>
<aop:after pointcut-ref="pc" method="doit" />
</aop:aspect>
</aop:config>
I just didnt debug..
The output is buffered, so the text comes before the "Hello world!", but the method is called afterwards..
I have AOP based loggin functionality with the following settings
Context xml configuration:
<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 properties:
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
Is there any way that I can disable the AOP invocations itself depending upon the enviroment?
I can disable the logging very easily but can I disable/enable the entire background process and invocations?
Please let if any clarifications are required.
Since you are using Spring AOP, one quick way to enable or disable aspects could be to simply use Bean profiles.
Define a profile say enableAOP:
Wrap the aop:config in say a configuration file under the specific profile
<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>
Now, whichever environment you want the specific aspects enabled, just run with enableAOP profile on.
it's been a while since this question was asked, but here is what I came up with for Spring 2:
Create an empty xml file (aop-context-off.xml) with an empty <beans> declaration.
Then create for example an aop-context-enabled.xml file with your AOP declaration.
Finally when importing the XML you could use :
<import resource="aop-context-${AOP_CONTEXT_SUFFIX:off}.xml" />
This will look for a system variable called AOP_CONTEXT_SUFFIX and if not found force the value to off.
So in the example above, by setting AOP_CONTEXT_SUFFIX to enabled it will load the aop-context-enabled.xml
So the switch being the system variable, you can easily Enable/Disable it at server start.