0

@ApplicationException annotedクラスで@Injectと@PostConstructメソッドが呼び出されないという問題があります。私は、サービス(= ejb)-layerでJPA、CDI、およびEJBとともにGlassfish 3.0.1を使用しており、sessionlanguageにテキストを含むerrorMessageをスローしたいと考えています。JEE6 - @ApplicationException - @Injectと@PostConstructが呼び出されない

I抽象ExceptionClass

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を提供するために注入されるべきであるとバンドルからerrormessageを取得します。 問題は、@PostConstructが何を試みても呼び出されないということです。私は@具体的なクラスに@Namedを付け加えて、抽象クラスではなく具象クラスで@Injectを使用しましたが、何も機能しません。私がinitText()を直接呼び出すと、(デバッガで)LocaleHandlerがインジェクトされていないことがわかります。

例外クラスとCDIに関する制限があるのか​​、それとも単に問題の原因を見つけられなかったのか、私は自分自身に尋ねています!

答えが分かりますか?事前に

ありがとう

トーマス

答えて

0

問題が解決されます。

私は古くから慣れていたように、単に例外をthrow new ConcreteException()として使用しました。間違いなくこれが問題でした。今度は私のEJBにConcreteExceptionを注入し、containercreatedフィールドを投げます。このように@Injectと@Postconstructは動作しています!

関連する問題