Exception handling JEE6-@ApplicationException-@Inject和@PostConstruct未调用

Exception handling JEE6-@ApplicationException-@Inject和@PostConstruct未调用,exception-handling,java-ee-6,code-injection,postconstruct,Exception Handling,Java Ee 6,Code Injection,Postconstruct,我对@ApplicationException注释类中未调用@Inject和@PostConstruct方法有问题。我将Glassfish 3.0.1与service=ejb层中的JPA、CDI和ejb一起使用,并希望抛出一条错误消息,其中包含sessionlanguage中的文本 我有一个抽象的例外类 public abstract class LocalizedException extends Exception { private static final long s

我对@ApplicationException注释类中未调用@Inject和@PostConstruct方法有问题。我将Glassfish 3.0.1与service=ejb层中的JPA、CDI和ejb一起使用,并希望抛出一条错误消息,其中包含sessionlanguage中的文本

我有一个抽象的例外类

 public abstract class LocalizedException extends Exception {
        private static final long serialVersionUID = 1L;


 String localizedMessage;

 //This method should be called as @PostConstruct from the concrete classe
protected void setLocalizedMessage(LocaleHandler localeHandler, String key){
    this.setLocalizedMessage(localeHandler, key, new Object());
}

protected void setLocalizedMessage(LocaleHandler localeHandler, String key, Object... args){
    localizedMessage = ErrorMessages.getErrorMessage(key,localeHandler.getAktuelleLokale(),args);
}

 @Override
 public String getMessage() {
  return localizedMessage;
 }

 @Override
 public String getLocalizedMessage() {
  return localizedMessage;
 }}
和一个具体的类别:

 @ApplicationException
        public class ConcreteException extends LocalizedException {
        private static final long serialVersionUID = 2615388267911318734L;
 private int userId;

 public ConcreteException(int userId) {
     this.userId=userId;
 }

 public int getUserId() {
  return userId;
 }

 @PostConstruct
 @Inject  
 public void initText(LocaleHandler localeHandler){
         setLocalizedMessage(localeHandler, "msgKey");
 }
}

应注入LocaleHandler=Sessionscoped以提供用于从捆绑包检索错误消息的currentLocale。 问题是,不管我怎么做,@PostConstruct都不会被调用。我甚至在具体类中用@Named,used@Inject来注释具体类,而不是抽象类,但没有任何效果。当我直接调用initText时,我可以在调试器中看到LocaleHandler没有被注入

现在我在问自己,是否有关于异常类和CDI的限制,或者我只是没有找到问题的根源

你知道答案吗

先发制人

托马斯:问题解决了

我只是将异常用作抛出新的ConcreteException,这是我多年来一直使用的。这就是问题所在。现在,我将ConcreteException注入EJB并抛出containercreated字段。这样@Inject和@Postconstruct就可以工作了