java - Is Spring able to handle this user case? Neither property nor constructor injection -
Basically, I have class A, which depends on class B, which in turn depends on the spring management Bean C, but I want to keep B as a class variable, for just a few reasons, inside a method Use B My solution is to create a static method (B) in B, which gives an example of B Now the problem is that, C is not properly injected into B.
// A can not be B. as class / field variable. Public class A {Pure Zero Method () gives an example of {BGT (B)}, but this example is not example example: it is a stable "example" in BBET (). (); // This eliminates a null poincé exception}} class B {@ resources (name = "c") private cc; Private static B example; Public stable b mill () {example example == blank? (Example = New B ()): Example; } Public Zero doSomething () {c.toString (); // This line will break if c // is not injected for instance of bug}} @ service ("C") class C {}
How do I solve this problem Do you? The whole thing to use spring is that it is a dependency injection framework, and the dependency of you are hardcoding in B.
Try very hard to do this if you do not want to store B in an instance variable, then pass it as an argument for the method.
If you are stubborn about doing so, you have to get an ApplicationContext and have to load it manually Optionally B can be implemented and after that you have the PropertiesSet method to present the current instance Can be registered with a constant frequency variable.