FAQs
Search
Recent Topics
Flagged Topics
Hot Topics
Best Topics
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Paul Clapham
Ron McLeod
Bear Bibeault
Liutauras Vilda
Sheriffs:
Jeanne Boyarsky
Tim Cooke
Junilu Lacar
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Jj Roberts
Carey Brown
Bartenders:
salvin francis
Frits Walraven
Piet Souris
Forum:
Aspect Oriented Programming
Spring AOP @AfterThrowing Advice not being executed
Roshni Chandrashekar
Greenhorn
Posts: 5
posted 7 years ago
The @AfterThrowing advice I have defined is not getting executed. Could some one take a look and please help me out? Below is the code I am using.
Pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>Test</groupId> <artifactId>Test</artifactId> <version>0.0.1-SNAPSHOT</version> <name>SpringAOPAfterThrowsTest</name> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.2.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.2.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>3.2.4.RELEASE</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.7.3</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.7.3</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>3.2.4.RELEASE</version> </dependency> </dependencies> </project>
spring-context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"> <aop:aspectj-autoproxy /> <bean id="loggingBean" class="com.aop.test.LoggingAspect" /> </beans>
LoggingAspect.java
package com.aop.test; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; @Aspect public class LoggingAspect { @AfterThrowing(pointcut = "execution(* com.aop..*.*(..))", throwing = "e") public void afterThrowingAdvice(final JoinPoint jp, final Exception e) { System.out.println("Exception is " + e.getLocalizedMessage()); System.out.println("Annotation driven:After throwing " + jp.getSignature().getName() + "()"); } }
SampleClassUnderAOP
package com.aop.test; public class SampleClassUnderAOP { public void sampleMethod() { String str = null; System.out.println(str.length()); } }
TestAOP
unit
test class
package com.aop.test; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "classpath:/spring-context.xml" }) public class TestAOP { @Test public void test() { SampleClassUnderAOP sc = new SampleClassUnderAOP(); sc.sampleMethod(); } }
Bill Gorder
Bartender
Posts: 1682
7
I like...
posted 7 years ago
You don't have an interface so the proxy is not being called. If you are going to go this route you need to force the use of CGLIB class proxying (or use full AspectJ rather than Springs)
Try
<aop:aspectj-autoproxy proxy-target-class="true"/>
[
How To Ask Questions
][
Read before you PM me
]
Nothing up my sleeve ... and ... presto! A tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Error creating bean 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcesso
Spring Major version '3' expected
Spring 3.0.2 and Active MQ 5.4.1 Issues
Error creating bean 'org.spring....PersistenceExceptionTranslationPostProcessor#0'
No mapping found for HTTP request with URI - Why erreur404
More...