[Java] The lifecycle method [methodName] must not throw a checked exception.

1 minute read

-Environment -Windows10 64bit version 1909 -openjdk 11 2018-09-25 -Eclipse IDE for Enterprise Java Developers Version: 2020-03 (4.15.0) -JSF 2.3.9

Phenomenon: When launching Payara, an error message is displayed

dialog error


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.

Cause: The method with @PostConstruct throws an exception

The method to which the PostConstruct annotation is applied must meet all of the following criteria: (Omitted) If this method throws an unchecked exception then this class should not be used unless the EJB is able to handle and recover from the exception.

HogePreviewController.java


    /**
     * Initialization process.
     * @throws HogeException exception.
     */
    @PostConstruct
    private void methodName() throws HogeException {
        // Processing that causes an exception...
        // Other processing...
    }

Support: Move processing to the f:viewAction method

HogePreviewController.java


    /** Initialization process. */
    @PostConstruct
    private void methodName() {
        // Other processing...
    }

    /**
     * Screen display processing.
     * @throws HogeException exception.
     */
    public void viewAction() throws HogeException {
        // Processing that causes an exception...
    }

hogePreview,xhtml


<h:head>
  <f:metadata>
    <f:viewAction action="#{hogePreviewController.viewAction()}" />
  </f:metadata>
</h:head>

Tags: ,

Updated: