Monday, June 5, 2017

spring injects into static class

Usually, a static class shall not depend on some specific object. But in some cases, we want to inject some env specific instance into the static class by Spring.
MethodInvokingFactoryBean can help on this. Here is one example

If the method has multiple arguments, here is the example

This xml setting let spring call one specific set method on one object or class(static) to inject the object from the spring container. This piece of xml setting can be repeated if multiple objects need to be injected.

No comments:

Post a Comment