1

I dont get it why i cannot use @Autowired in a expander class, it gives me NullPointer.

Heres my code:

public class ClassExpander implements Expander {

     @Autowired EncryptFieldService encryptionService;

     private RollTokenEncoder tokenEncoder;

     @Override public String expand(Object value) {
         System.out.println(tokenEncoder);
         return encryptionService.encrypt(value.toString());
     }

     @Autowired
     public final void setTokenEncoder(RollingTokenEncoder tokenEncoder) {
         this.tokenEncoder = tokenEncoder;
     }
 }

Funfact that these beans is working when i call it on my builder. But i need it to work with expanders..

Any help?

Anish B.
  • 9,111
  • 3
  • 21
  • 41
  • Are you letting spring create the instance or are you creating the instance yourself ? – JEY Sep 17 '20 at 15:02
  • Im giving it all to spring, man... I think it must be something with the scope.. When i start my service, that beans works just fine with feign. The feign builder works fine and i can utilize those beans there.. But when its called by expander, it gives me null instance – Caio Rodrigo Sep 17 '20 at 15:18

0 Answers0