It's not a secret anymore!*
The moose likes Spring and the fly likes Struts 2 + Spring 3 +Hibernate 3.5 Integration Problem session factory nullpointer exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Struts 2 + Spring 3 +Hibernate 3.5 Integration Problem session factory nullpointer exception" Watch "Struts 2 + Spring 3 +Hibernate 3.5 Integration Problem session factory nullpointer exception" New topic
Author

Struts 2 + Spring 3 +Hibernate 3.5 Integration Problem session factory nullpointer exception

Tony Manello
Greenhorn

Joined: Aug 11, 2010
Posts: 13
Hi I'm new using these frameworks. I've used this tutorial as a starting point. My problem is that none of my actions work. When the jsp input form is shown and you submit the values I get this error:




My Spring application context is as follows:



My hibernate.cfg is:



Struts.xml:



The base action is:




And the Login action:



I've tried to substitute in Login.action by and this way this action works fine and the rest keep showing the error. So I think maybe there is a problem with the session factory, but I can't see the problem in the configuration.

Thanks in advance.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Without knowing what line the error message actually corresponds to it's difficult to help.

I don't see anywhere were you attempt to set logicaComun, though.
Tony Manello
Greenhorn

Joined: Aug 11, 2010
Posts: 13
The error line corresponds to this line of Login action class:



I forgot including the bussiness class LogicaComun:



When I try to use any method of the bussiness layer in an action in which is injected factory session, I get the error in the web browser.

LogicaComun (the bussiness layer or DAO), in the same way as session factory before, is injected to AccionBase action and it's Spring the responsible of injecting the bussiness sinlgeton in it.

All of this is the expected behaviour I understood from the tutorial, but I guess I'm wrong.

Any idea?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

But you *don't* inject it anywhere, that's what I'm saying. Where and how do you believe it's being set on the action?
Tony Manello
Greenhorn

Joined: Aug 11, 2010
Posts: 13
I understand what you say but now I'm so confused. According to this reference documentation is not need to set the reference by yourself because Spring's context do that with declared beans. So if I reference the bean "session factory" in the DAO LogicaComun with

and then I do the same with bean DAO in the Base Action (AccionBase)


It should be ok shouldn't it?

What am I doing wrong?

Thanks for your patience!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

But your bean is named something else:I'm also assuming you're deploying the Struts 2 Spring plugin... although I don't actually know if it works with Spring 3 or not; I've never tried.
Tony Manello
Greenhorn

Joined: Aug 11, 2010
Posts: 13
I'm using Struts2 Spring plugin and it works at least with an example.

I changed the name reference for dependency injection in AccionBase from

to

Now it seems to work OK. So as you said the problem was the bean name

Thanks a lot David!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 + Spring 3 +Hibernate 3.5 Integration Problem session factory nullpointer exception
 
Similar Threads
org.apache.struts2.json.JSONWriter
strtus 2 application error
Hibernate Core Session / Transaction injection problem with struts2 and tiles
NullPointerException at the SessionFactory create line.
Conversion of string to date