This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes Struts 2.1.6 | Hibernate 3 | Spring 2.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Struts 2.1.6 | Hibernate 3 | Spring 2.5" Watch "Struts 2.1.6 | Hibernate 3 | Spring 2.5" New topic

Struts 2.1.6 | Hibernate 3 | Spring 2.5

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
I don't really know which forum to put this under as it covers all these products.

I am posting to ask if anyone out there has a simple working example of a app (WAR) using the above with annotations, as I have tried and tried and tried, but just can not get anywhere and my attempts are now such a mess I don't know where to go from here.

It seems all the examples I find on the Internet just don't work, people tell you to do things in a different way or JARs are wrong, etc etc etc.


Thanks in advance

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
I have worked my way through Manning's Struts2 in Action which is an excellent book.

They however, work with Struts 2.0.x. The annotation configuration is quite simple.
You need to pass the FilterDispatcher in the web.xml a param called 'actionPackages' and as the value the packages that contain Action classes.

The Action classes themselves need to either end in Action (e.g. RegisterAction) or implement the Action interface (typically by extending ActionSupport).

The framework then scans the corresponding classes for annotations, which are generated like this

Note that you do not specify a namespace. This is done by convention.

The namespace goes together by the package name + the Action class name minus the Action.

e.g. test.testPackage.RegisterAction

results to http://localhost:8080/PROJECT_NAME/test/testPackage/Register.action

This works perfectly well for Struts 2.0.x

In Struts 2.1.x however, they have changed the organization of jars plus the annotation syntax, which I was to lazy to go after so far ;-)

Happy frameworking!

JDBCSupport - An easy to use, light-weight JDBC framework -
David Newton

Joined: Sep 29, 2008
Posts: 12617

Without saying what's wrong it's completely impossible to help.

I'm running several apps under Struts 2.1, Hibernate 3, and Spring 2.5, so it's possible. For my money it'd be easier to approach it piecemeal: get a simple S2.1 app working, add Spring, then add Hibernate.
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
After a relentless number of errors regarding missing classses or JAr files I have decided to dicth the Spring part for now as to be honest I don't really understand what it offers me that I can't do with just Struts & Hibernate.
I found this link which shows a basic Struts/Hibernate app which I have followed but made a couple of minor changes as I am looking to use annotations over XML

However when running this app I get the following error on the line (
[sessionFactory = (new AnnotationConfiguration()).configure().buildSessionFactory();]

I have attached teh war file as it stands

Cheers in advance for anything that anyone can add to help with this issue.


The code bit:


I'm sure these must not all be needed!
David Newton

Joined: Sep 29, 2008
Posts: 12617

No, that looks to be more or less the right list of jars. Have you checked for the root cause of the exception?

Spring offers quite a bit more than just S2/Hibernate; it can handle all the DI/IoC chores (although S2 uses an early, hacked verison of Guice IMO the current Spring stuff is preferable), allows declarative transactions, can handle security tasks, blah blah blah.
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Sorry thought I included that, there is nothing in the server logs.
David Newton

Joined: Sep 29, 2008
Posts: 12617

That's unusual--do you have logging configured correctly and the logging levels turned up?

Stack traces usually include information, like... well, the stack trace.

One thing Spring would let you do, btw, is inject the service DAO being used in your action. Using DI/IoC *greatly* improves the testability of your actions. Services should generally be coded to an interface, not a specific implementation, for this to be the most versatile. The S2 Spring plugin makes Spring integration seamless and essentially invisible for many (most?) usecases.

Also note that in S2.1 you'll want to use one of the .ng package dispatchers, although the earlier versions may still work.

I don't know the full dependency tree for Hibernate; that's one reason why something like Maven and/or Ivy is really handy.
I agree. Here's the link:
subject: Struts 2.1.6 | Hibernate 3 | Spring 2.5
Similar Threads
struts2 properties file reload
Ask about Struts2.1 JQuery integration
Anyone here a fan of old school RPGs?
Problem with listFiles
URLyBird1.3.2 A question about Exception handling of some "fatal" errors.