aspose file tools*
The moose likes Spring and the fly likes Not able to understant object initialisation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Not able to understant object initialisation" Watch "Not able to understant object initialisation" New topic
Author

Not able to understant object initialisation

Rahul Shivsharan
Ranch Hand

Joined: Jun 17, 2009
Posts: 83
Performer.java file


Juggler.java file


bean-prac-cfg.xml file


MainPractise04.java file, which i run ,


When i run the above file, the program runs fine and prints the sop in method perform();

but when i switch the xml file to new xml ie. bean-cfg.xml as follows,



and in MainPractise04.java, i change the path of called xml to bean-cfg.xml,
the perform() method is not called and i get Nullpointerexception, ie. obj is still null, thought the constructor sop of Juggler.java is called

why so ?

Rahul Shivsharan
Ranch Hand

Joined: Jun 17, 2009
Posts: 83
this the output, of the above code when i add bean-cfg.xml, and run MainPractise04.java from command prompt

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Do me a favor and change the following.

Remove the try catch, no Idea why you need that there. It looks to me like you are trying things out, and the exception if thrown will be printed out anyway.

change

BeanFactory beanFactory = null;
beanFactory = new ClassPathXmlApplicationContext("bean-prac-cfg.xml");


so your code to start should look like this



That is much cleaner and what you should be doing using either Spring 2.5.6 or Spring 3.x

If you are trying to learn on an older version of Spring, I recommend using the latest.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

As far as your error, what is different. I would say the other beans, so I would say one of the other beans has a problem. And I am going to guess, because the stack trace is too short there to show the real error. (By the, way read exceptions in Spring from bottom up, looking for the true root cause of the exception) I would say it is the initBean that is the cause of the problems.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to understant object initialisation