0

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.

Jens
  • 67,715
  • 15
  • 98
  • 113
Amir_Af
  • 576
  • 6
  • 22
  • Looks like the log4j.XML is not in the classpath of your application – Jens Jun 29 '16 at 13:51
  • It is , if not all other appenders shouldn't work as well but they are working. – Amir_Af Jun 29 '16 at 13:52
  • Where is the file located and what is the Content of it? – Jens Jun 29 '16 at 13:53
  • 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 Jun 29 '16 at 13:56
  • Yes, the issue was missing appender for the spring web package. Thanks for the help – Amir_Af Jun 29 '16 at 14:03

2 Answers2

1

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

Community
  • 1
  • 1
Bhanu Pasrija
  • 137
  • 2
  • 9
0

Issue was missing log4j appender for the spring package.

<logger name="org.springframework.web">
  <level value="debug"/>
  <appender-ref ref="CONSOLE"/>
</logger>
Amir_Af
  • 576
  • 6
  • 22