LoginSignup
0
0

More than 3 years have passed since last update.

The lifecycle method [methodName] must not throw a checked exception.となったときの対応方法

Last updated at Posted at 2020-08-25
  • 環境
    • Windows10 64bit バージョン1909
    • openjdk 11 2018-09-25
    • Eclipse IDE for Enterprise Java Developers Version: 2020-03 (4.15.0)
    • JSF 2.3.9

事象 : Payaraを起動したらエラーメッセージが表示された

ダイアログのエラー
cannot Deploy app-name
deploy is failing=Error occurred during deployment:
 Exception while deploying the app [app-name] :
 The lifecycle method [methodName] must not throw a checked exception. Related annotation information:
 annotation [@javax.annotation.PostConstruct()] on annotated element [private void jp.co.ponsuke.controller.HogePreviewController.methodName() throws jp.co.ponsuke.core.dto.HogeCd$HogeException] of type [METHOD].
 Please see server.log for more details.

原因 : @PostConstructをつけたメソッドで例外をthrowしているから

PostConstruct注釈の適用先のメソッドは、次の基準をすべて満たす必要があります。
(省略)
このメソッドが非チェック例外をスローする場合は、EJBで例外の処理および例外からの回復が可能である場合を除いて、このクラスを使用してはいけません。
PostConstruct (Java Platform SE 8)

HogePreviewController.java
    /**
     * 初期化処理.
     * @throws HogeException 例外.
     */
    @PostConstruct
    private void methodName() throws HogeException {
        // 例外が発生する処理...
        // その他の処理...
    }

対応 : 処理をf:viewActionのメソッドに移動する

HogePreviewController.java
    /** 初期化処理. */
    @PostConstruct
    private void methodName() {
        // その他の処理...
    }

    /**
     * 画面表示処理.
     * @throws HogeException 例外.
     */
    public void viewAction() throws HogeException {
        // 例外が発生する処理...
    }
hogePreview,xhtml
<h:head>
  <f:metadata>
    <f:viewAction action="#{hogePreviewController.viewAction()}" />
  </f:metadata>
</h:head>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0