I am a new guy to Dependency injection and I have tried something different. Can anyone please help me out...!!!
I have a web application with following requirements:
1. People will write the name of the class in an xml file.
2. They will also write their variable name in the same xml, for which you have to load a string value.
I have done something like this:
1. I have written a startup servlet, where I am loading the xml file location as a stream.
2. Using DOM, I am parsing the xml file and fetching all the required data.
3. In my dependency injection class, I am first loading the class as follows:
Class actualClass = Class.forName(classValueInXML):
Object actualObject = actualClass.newInstance();
Field acutalField = actualClass.getDeclaredField("Stranger");
actualField.set(actualObject, "I am an stranger");
4. The above code is running absolutely fine.
5. Now when I am trying to execute the same file by calling it from some other place, then it says, Stranger not initialized. NullPointerException.
I am new to this. Please anyone, help me !!!
Thanks in Advance !!!
OCBCD (EJB 3), OCJP (Java SE 6), MCTS (MS SQL Server 2005)