部分非託管類我在我的代碼創建MyClass類的衆多對象。天色管理,在Java春天
public class MyClass {
private String a;
private Integer b;
private SomeObject c;
public A(String a, Integer b, SomeObject c) {
this.a = a; this.b = b; this.c = c;
}
}
反正我有可以使用Spring只是SomeObject注入到這個類,當我創建的MyClass的對象。 MyClass的是不春季管理,因爲我需要以隨機方式產生在我的代碼相同的對象。我如何解決這個問題。
我做的getBean在我的SomeObject主要方法,並把它傳遞到MyClass的,每當我創造它的對象。
我創建了一個SomeObjectSingleton這是了ApplicationContextAware(它本身做了的getBean得到SomeObject)。我直接在MyClass構造函數中調用SomeObjectSingleton.getImpl。
你認爲哪種方式最合適,還是有其他更好的方法來解決這個問題。