我需要将全局异常处理程序添加到我的项目中,以便捕获EGB容器中所有未捕获的异常。
我读过关于使用新线程来捕获未捕获的异常的方法,但这对我没有帮助。
EJB还有其他的想法吗??
发布于 2014-08-31 20:41:40
afaik没有全局处理异常的interceptor,但你有没有考虑过使用API来解决这个问题?
拦截器类:
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;
}
}
}ejb-jar.xml中的默认拦截器映射:
<?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>https://stackoverflow.com/questions/25591856
复制相似问题