Question

Is this done via Reflection, or ServiceLoader? I am asking, because I have a custom LoginModule which is supposed to use Spring, but despite having @Autowired, the respective bean is not getting populated properly (with the bean defined in the context, which is clearly on the classpath). This leads me to think that the LoginModule implementing class is being loaded using reflection and thus circumventing Spring completely. Is this the case? Can I still somehow use Spring, if so?

Was it helpful?

Solution

To answer my own question: yes, this is done using reflection, which effectively goes around Spring and gives you an instantiated object that doesn't have anything @Autowired.

However, you could manually initialize your beans in your LoginModule's initialize() method. The LoginModule class should implement org.springframework.context.ApplicationContextAware and you must have a private static ApplicationContext context. This way the context is injected for you and you can load the beans from there on.

Far from optimal, but it seems to be doing the trick. If anybody has a better solution, please share it, as I would be happy to hear it!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top