Hi there,
I'm trying to setup a simple exception handling for my app. The app context is spread over several xml files. Consider the following code:
Let's assume this code resides in aop-context.xml and let's assume I have a bunch of other context files. Now if I initialize the app using aop-context.xml as the single context descriptor - everything works fine, i.e. my Advice (see below) is called upon an exception. However if the other remaining xml files are added to app context, the Advice afterThrows method is not called.Code:... <aop:config> <aop:pointcut id="serviceMethod" expression="execution(* my.app.services.*.*(..))" /> <aop:advisor pointcut-ref="serviceMethod" advice-ref="exceptionAdvice" /> </aop:config> <bean id="exceptionAdvice" class="my.app.aop.MyExceptionAdvice" /> <bean id="service" class="my.app.services.DummyServiceImpl" /> ...
So, here's some code to make it all more clear:
So, if I run a simple test app using the code below - everything works just fine:Code:// the advice public class MyExceptionAdvice implements ThrowsAdvice { public void afterThrowing(Exception e) { System.out.println("Yep, there was an exception, do something!"); } } // service interface and implementation public interface DummyService { public void testService(); } public class DummyServiceImpl { public void testService() { throw new IllegalArgumentException("WHOOOPS!"); } }
This however doesn't - the advice doesn't receive any exceptions:Code:public class AopTest { public static void main(String[] args) { String[] paths = {"aop-context.xml"}; ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(paths); DummyService service = (DummyService) ctx.getBean("service"); service.testService(); } }
Code:public class AopTest { public static void main(String[] args) { String[] paths = {"aop-context.xml", "application-context", "jdbc-context.xml", "directory-context.xml"}; ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(paths); DummyService service = (DummyService) ctx.getBean("service"); service.testService(); } }
Any ideas? It's really driving me mad
TIA,
jenner



Reply With Quote
