Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • var1 and var2 values should be passed from Main class. Those are not constant values. Can I configure that in applicationContext.xml file? Commented Sep 29, 2011 at 19:33
  • That is not what you use Spring for. Dependency injection is about setting your dependencies up outside of code. What is it that you are trying to do? Commented Sep 29, 2011 at 19:49
  • "Main" class defines 2 variables. "Test" class is instantiated from "Main" class and should pass those 2 variables to "Test" class. How can I acheive this using Spring. For Ex: Main Class: int var1 = getValueFromDatabase(1); int var2 = getValueFromDatabase(2); Test test = new Test(var1, var2); Commented Sep 29, 2011 at 19:57
  • I understand your example, but Spring is not necessary to create an instance of Test in this case. Here, you should create Test using the new operator just as you have shown: Test test = new Test(var1, var2); Commented Sep 30, 2011 at 4:00