2014-08-31 3 views
0

EGB 컨테이너에서 모든 잡히지 않은 예외를 잡기 위해 전역 예외 처리기를 프로젝트에 추가해야합니다.EJB 전역 예외 처리기

새로운 스레드를 사용하여 캐치되지 않은 예외를 잡는 방법에 대해 읽었지만 저에게 도움이되지 않습니다.

EJB 용으로 다른 아이디어가 있습니까?

답변

2

afaik를 예외적으로 처리하는 데 필요한 API가 없지만 여기에 interceptor을 사용 해본 적이 있습니까?

인터셉터 클래스 :

<?xml version="1.0" encoding="UTF-8"?> 
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"> 
    <interceptors> 
     <interceptor> 
      <interceptor-class>test.Interceptor</interceptor-class> 
     </interceptor> 
    </interceptors> 
    <assembly-descriptor> 
     <interceptor-binding> 
      <ejb-name>*</ejb-name> 
      <interceptor-class>test.Interceptor</interceptor-class> 
     </interceptor-binding> 
    </assembly-descriptor> 
</ejb-jar> 
: EJB-jar.xml의에서

package test; 

import javax.interceptor.AroundInvoke; 
import javax.interceptor.InvocationContext; 


public class Interceptor { 

    @AroundInvoke 
    public Object exceptionHandler(InvocationContext ctx) throws Exception { 
     try { 
      return ctx.proceed(); 
     } catch (RuntimeException re) { 
      // Do something with the exception 
      throw re; 
     } 
    } 
} 

기본 인터셉터 매핑