Issue
I have problem while using spring boot. This example of code:
@Component
class Bat extends OtherLibrary{
@Autowired
public Life var;
@PostConstruct
public void registerBat(){
OtherLibraryApi api = new otherLibraryApi()
api.register(new Bat());
}
@Override
public void onResponce(ResponceVal respVal){
Life sum = respVal.getLife().add(var);
}
}
Class Bat extends third party library class OtherLibrary. Thrid party library has abstract method onResponce that this library asynchronously call at some method. The problem is that when onResponce method is called it doesn't include spring context so autowired field var in method onResponce has null value.
How can I include spring context in third party library method for using autowired fields ?
Solution
api.register(new Bat());
this is definitely wrong (from Spring perspective)! I am not sure but how about passing this
instead of new Bat()
? This way the Spring managed version of Bat
class will be registered.
e.g.
api.register(this);
Answered By - pleft