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

--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

Event: An error message was displayed when starting Payara

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: Because 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, you should not use this class unless the EJB allows you to handle and recover from the exception.

HogePreviewController.java


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

Action: Move the process to the method of f: viewAction

HogePreviewController.java


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

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

hogePreview,xhtml


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

Recommended Posts

The lifecycle method [methodName] must not throw a checked exception.
must not return in the for statement