Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullPointerException in GenericFilterBean on Spring Boot application start after adding a custom filter

NullPointerException in GenericFilterBean on Spring Boot application start after adding a custom filter that extends OncePerRequestFilter.

Here is the stack trace:

Caused by: java.lang.NullPointerException: Cannot invoke "org.apache.commons.logging.Log.isDebugEnabled()" because "this.logger" is null at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:241)

We are using Spring Boot version 2.7.6.

Any solution for this issue?

like image 548
Valsaraj Viswanathan Avatar asked Dec 18 '25 18:12

Valsaraj Viswanathan


1 Answers

I had the same problem with the Spring Boot app and Micrometer. I realized that you cannot use Micrometer annotations whenever you want. It happens because of the Proxy mechanism. JDK Dynamic Proxy can only create proxy if the target class implements at least 1 interface whereas CGLIB Proxy has no such limitation and is able to create proxy as long as the target class / method is non-final. This is important because it will help us understand why Spring AOP will not work on OncePerRequestFilter class.

like image 111
Sergei Golitsyn Avatar answered Dec 21 '25 08:12

Sergei Golitsyn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!