I don't know whether this is a bug or a mistake of mine. I have situation where I call a feign client. It works fine, until I try putting the feign client inside a thread (simplified version):

final Runnable t = new Runnable() {
    @Override
    public void run() {
        try {
            feignUserClient.findByEmail("someEmail@address.com");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
};
new Thread(t).start();

When I try to do it, I get (printed by the real version, not the simplified one above):

    java.lang.NullPointerException
    at br.alfa.tutoria.AlfaTutoriaApplication$1.apply(AlfaTutoriaApplication.java:46)
    at feign.SynchronousMethodHandler.targetRequest(SynchronousMethodHandler.java:158)
    at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:88)
    at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
    at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
    at com.sun.proxy.$Proxy246.findByEmail(Unknown Source)
    at br.alfa.tutoria.service.impl.TutoriaServiceImpl.atribuiFuncaoTutor(TutoriaServiceImpl.java:285)
    at br.alfa.tutoria.service.impl.TutoriaServiceImpl$2.run(TutoriaServiceImpl.java:270)
    at java.lang.Thread.run(Unknown Source)

The feignUserClient is @Autowired (I've tried turn it final, and inject it using a constructor, but it made no difference - anyway, it's value is not null when the code is executed).

Comment From: ryanjbaxter

Could you perhaps show the entire class file?

Comment From: spencergibb

No need to cross post.

Closing in favor of https://stackoverflow.com/questions/45016756/feign-client-called-from-a-thread

Comment From: julianobrasil

@ryanjbaxter, which class? The feign interface? Or the one which is calling the feign?

Well:

Interface:

@FeignClient(name = "authUsers", url = br.alfa.tutoria.config.Url.AUTH_SERVER)
public interface UsuarioFeign {
    @RequestMapping(value = "/user-search-by-email", method = RequestMethod.POST)
    public User findByEmail(String email);
}

The other class, which call... is doesn't matter. I tried it in several diferent classes (all of them annotated with @RestController or @Service). It just stop working if I put it in a thread.

Well, I'm gonna post this information in stackoverflow and track it over there.

Comment From: nitheshsiddapura

Could you perhaps show the entire class file?

check weather you have created bean with @autowired annotation of feignUserClient