File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes GOF Singelton class in Spring 3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "GOF Singelton class in Spring 3" Watch "GOF Singelton class in Spring 3" New topic
Author

GOF Singelton class in Spring 3

Praveen Kumar Singh
Ranch Hand

Joined: Mar 04, 2009
Posts: 43
Hi,
I am trying to built an GOF type (not spring DI singleton) Singleton class in spring.



As, it is clear that to access the bean "userAuthenticationService", i need to fetch it from application context, hence i need to configure PrivilegesMgr in application context
After some R&D, i got the way




My problem is
Singleton class, traditionally called as PrivilegesMgr.getInstance() and not privilegesMgr.getInstance()

when, try to do PrivilegesMgr.getInstance(), i get null pointer, which is logical, as their is no bean available.
Any suggestion ?

Praveen
SCJP, SCWCD, SOA
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

Moving to our Spring forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Praveen Kumar Singh
Ranch Hand

Joined: Mar 04, 2009
Posts: 43
Any update guys?
Praveen Kumar Singh
Ranch Hand

Joined: Mar 04, 2009
Posts: 43
GOF = Gang of four
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Singleton class, traditionally called as PrivilegesMgr.getInstance() and not privilegesMgr.getInstance()


Yes, it's considered bad form to call a static method through it's class rather than an object reference, but there is really no difference in Java - it works either way. There's also no need to call "getInstance()" explicitly in your code - Spring has already called "getInstance()" for you - you can just call it as:



when, try to do PrivilegesMgr.getInstance(), i get null pointer, which is logical, as their is no bean available.


Why do you think there is no bean available? The code you posted looked OK - are you sure you're loading the beans XML configuration containing your "privilegesMgr" bean? Can you post relevant sections from your web.xml deployment descriptor?

-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GOF Singelton class in Spring 3