I have following situation. There is POJO which has autowired implementation of an interface, using some spring magic as shown bellow. However this dependency doesn't get resolved if creation of channels is managed via spring bean. It only works if POJO factory creates channels. Example bellow.
@Controller
public class Test{
@RequestMapping(value = "/load", method = RequestMethod.GET)
public @ResponseBody String testConfiguration() {
// this is pojo and here it works, channels within have wired interface implementation
StaticFactory.getChannels(null);
// if i call same method within spring managed bean (@Service)
// then it doesnt work
System.out.println("channels created");
return "alive";
}
}
Created Channels are POJO but they have autowired interface implementation, which should be enabled with the following in constructor:
public DummyChannel() {
// enables dependency injection of spring managed beans into POJO
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}
public class StaticFactory {
public static List<SmppChannel> getChannels(Map<ChannelMode, Integer> channelsDefinition) {
List<SmppChannel> dummyChannels = new ArrayList<>();
DummyChannel d = new DummyChannel();
// dummyChannel.sendSms("bla");
System.out.println("here");
// dummyChannels.add(new DummyChannel());
return dummyChannels;
}
}
Now, this thing works if i have non-spring managed Factory. Regardless if mentioned factory is static or not, when it creates channels, they have properly wired interface implementation. However, if i copy paste exactly same code form the factory into Spring managed Bean annotated with @Service, wired dependency is null in created channel. Could somebody tell me what am i missing here, why things get injected when the factory of channels is not managed by the Spring ?
Aucun commentaire:
Enregistrer un commentaire