Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread.setDefaultUncaughtExceptionHandler in Spring

I am developing a Spring application, and was wondering if there a part of the framework that let's me do something like this in a more elegant way, such as configuring something in XML?

like image 892
mogronalol Avatar asked Feb 10 '12 14:02

mogronalol


1 Answers

If the purpose of your question is to set a custom UncaughtExceptionHandler through your application context, you can use:

<bean id="myhandler" class="java.lang.ThreadGroup">
    <constructor-arg value="Test"/>
</bean>

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
   <property name="targetClass" value="java.lang.Thread"/>
   <property name="targetMethod" value="setDefaultUncaughtExceptionHandler"/>
   <property name="arguments">
     <list>
         <ref bean="myhandler" />
     </list>
   </property>
</bean>

(N.B. replace myhandler with an Thread.UncaughtExceptionHandler of choice...)

like image 139
beny23 Avatar answered Oct 12 '22 21:10

beny23