问题
My ear application was working fine. But suddenly it started to throw javax.ejb.EJBException in some method calls, instead of returning the original Application Exception (annotated with @ApplicationException(rollback=true). Now the original application exception is wrapped in the EJBException. the Currently the other developer who was working in the project is on leave. Therefore I have no idea what he has done to the code for happening this. This application exception and ejb remote interfaces are in a separate jar file which is deployed as a shared library in the weblogic.
I would like to know what can be responsible for throwing this EJBException instead of throwing the application exception. I think may be @ApplicationException annotation is not correctly detected by the weblogic. Could anyone give me a help to resolve this issue?
回答1:
I was able to solve the issue by adding the application exception in the "throw" clause of ejb method signature.
Previously all ejb classes and application exception class was in the same jar file. But later the application exception class and ejb remote interfaces were put to another jar file called "api" jar file and the relevant ejb files were kept in the previous jar file.
It seems it is enough to declare an application exception with @ApplicationException, if we need it to treat as an application excpetion when all classes are in the same jar file. But if the application exception class is in a separate jar file, we need to add this application exception in the "throw" clause of the ejb method signature to interpret it as an application exception by the weblogic server.
来源:https://stackoverflow.com/questions/15387346/weblogic-wrap-application-exception-in-javax-ejb-ejbexception