0
votes

I created ExcpetionHandler class which annotated with @ControllerAdivce annotation which working fine using eclipse tomcat server.

While I build the project and deploy it to tomcat on some unix machine , the exceptionHandler not getting triggerd.

I noticed that some log4j warning getting generated only on the unix machine .

The log4j xml is configured and all appenders are working .

Only after adding the below class I start to get the below log4j messages.

Any idea ?

@ControllerAdvice
public class ExceptionController {

    @ExceptionHandler(RuntimeException.class)
    public ResponseEntity<ClientErrorMessage> handleRunTimeException(HttpServletRequest request, RuntimeException exception) {
       ClientErrorMessage message = SOME_MESSAGE
       return new ResponseEntity<>(message, HttpStatus.INTERNAL_SERVER_ERROR);
    }

}

log4j:WARN No appenders could be found for logger (org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

2
Looks like the log4j.XML is not in the classpath of your applicationJens
It is , if not all other appenders shouldn't work as well but they are working.Amir_Af
Where is the file located and what is the Content of it?Jens
I provided the path by providing JAVA_OPTS -Dlog4j.configuration. I might found the issue , will test it and update. i think i need to add appender for org.springframework.web package. currently i don't have appender for this.Amir_Af
Yes, the issue was missing appender for the spring web package. Thanks for the helpAmir_Af

2 Answers

1
votes

You can check the following link for your question. It seems that you are using logger instance before configuring log4j

No appenders could be found for logger(log4j)?

0
votes

Issue was missing log4j appender for the spring package.

<logger name="org.springframework.web">
  <level value="debug"/>
  <appender-ref ref="CONSOLE"/>
</logger>