java - Spring HttpSecurity - Filter Dependency Injection -
in web application, have created custom filter adding current login details org.slf4j.mdc . application uses spring boot , spring security configured purely using annotations.
here relevant parts of spring configuration,
@configuration @enablewebsecurity public class securityconfiguration extends websecurityconfigureradapter{ @inject private customfilter customfilter; // @override protected void configure(httpsecurity http) throws exception { http.addfilter(customfilter); } } the above code doesn't work. exception
caused by: java.lang.illegalargumentexception: can not set com.example.web.filter.customfilter field com.example.config.securityconfiguration.customfilter com.sun.proxy.$proxy202 @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:164) [rt.jar:1.7.0_25] @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:168) [rt.jar:1.7.0_25] @ sun.reflect.unsafeobjectfieldaccessorimpl.set(unsafeobjectfieldaccessorimpl.java:81) [rt.jar:1.7.0_25] @ java.lang.reflect.field.set(field.java:741) [rt.jar:1.7.0_25] @ org.springframework.beans.factory.annotation.autowiredannotationbeanpostprocessor$autowiredfieldelement.inject(autowiredannotationbeanpostprocessor.java:505) [spring-beans-4.0.7.release.jar:4.0.7.release] ... 76 more but 1 work.
@configuration @enablewebsecurity public class securityconfiguration extends websecurityconfigureradapter{ // @override protected void configure(httpsecurity http) throws exception { http.addfilter(new customfilter()); } } in knowledge recommended let spring container manage initialization why tried first approach. can tell me why dependency injection failing addfilter() method?
ps: have tried addfilterafter method also, same result. customfilter extends securitycontextholderawarerequestfilter, use addfilter().
Comments
Post a Comment