views:

24

answers:

1

In Spring MVC, an exception's stack trace is logged if it makes it all the way back up to the framework (for example, if there is a NullPointerException). Is there a simple way to do this using Spring's MBeanExporter?

I know that I could have try-catches in the method to do this, but that would lead to clutter. I checked the Spring documentation (Chapter 22 is the one on JMX) and didn't see anything. I also haven't seen anything on SO. I also looked at the source code for MBeanExporter, and there seems to be a way to register listeners for MBean registration, but not for MBean request handling.

A: 

MBeanExporter is a very flexible thing, and can handle many different situations. Since you showed us no sample code, I'll assume you're using the annotations @ManagedOperation and @ManagedAttribute, since those seem to be the most common.

If you have a getter method annotated with @ManagedAttribute, and this getter throws an exception, then this will not be logged anywhere, it will just be propagated to the client for it to handle. This is sometimes annoying, but there seems to be no way of configuring it to do otherwise.

@ManagedOperation methods, however, will have their exceptions caught and logged. I don't know why this distinction is made, but that's the way it is.

skaffman
I wasn't using any annotations - Spring seems to by default export all the operations/attributes. I'll try adding an annotation on the operation in question and see what that does, thanks.
James Kingsbery