Spring AOP + AspectJ annotation example

In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simple, Spring AOP + AspectJ allow you to intercept method easily. Common AspectJ annotations : @Before – Run before the method execution @After – Run after the method returned a result @AfterReturning – Run after the method returned a …

Read more

Spring AOP transaction management in Hibernate

Transaction management is required to ensure the data integrity and consistency in database. Spring’s AOP technique is allow developers to manage the transaction declarative. Here’s an example to show how to manage the Hibernate transaction with Spring AOP. P.S Many Hibernate and Spring configuration files are hidden, only some important files are shown, if you …

Read more

Spring AOP Example – Pointcut , Advisor

In last Spring AOP advice examples, the entire methods of a class are intercepted automatically. But for most cases, you may just need a way to intercept only one or two methods, this is what ‘Pointcut’ come for. It allow you to intercept a method by it’s method name. In addition, a ‘Pointcut’ must be …

Read more

Spring AOP Example – Advice

Spring AOP + AspectJ Using AspectJ is more flexible and powerful, please refer to this tutorial – Using AspectJ annotation in Spring AOP. Spring AOP (Aspect-oriented programming) framework is used to modularize cross-cutting concerns in aspects. Put it simple, it’s just an interceptor to intercept some processes, for example, when a method is execute, Spring …

Read more

Spring AOP Error : Cannot proxy target class because CGLIB2 is not available

In Spring AOP, you have to include the cglib library into your build path to avoid the “Cannot proxy target class because CGLIB2 is not available” error message. Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘customerServiceProxy’: FactoryBean threw exception on object creation; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 …

Read more

Spring AOP Interceptor transaction is not working

Problem The Spring AOP transaction is not working in following interceptors? <bean id="testAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="interceptorNames"> <list> <idref bean="urlInterceptorInsert" /> <idref bean="urlInterceptorCommit" /> <idref bean="urlInterceptorRelease" /> <idref bean="matchGenericTxInterceptor" /> </list> </property> <property name="beanNames"> <list> <idref local="urlBo" /> </list> </property> </bean> The “matchGenericTxInterceptor” transaction interceptor, suppose to intercept urlInterceptorInsert, urlInterceptorCommit,urlInterceptorRelease, but it’s not work as expected? …

Read more